ReUsing a defined object - by redefining it

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I reuse an object that is already defined. I want to delete some files using the FileInfo class and the "name" is a read only property so I can't set the name as I want to. I don't want to delete all the files only a few of them in different Directories

For example this gives me an error. Is there a way to reset "FI" in this case...

FileInfo FI = new FileInfo(string.Concat(strIadsPath, "\\etc\\", myDataRow["Name"].ToString(), ".ini"))
if (FI.Exists
FI.Delete()

// delete the bookmark fil
FileInfo FI = new FileInfo(string.Concat(strIadsPath, "\\bookmark\\", myDataRow["Name"].ToString(), ".bmk"))
if(FI.Exists
FI.Delete()
 
Bob said:
How can I reuse an object that is already defined. I want to delete
some files using the FileInfo class and the "name" is a read only
property so I can't set the name as I want to. I don't want to delete
all the files only a few of them in different Directories.

For example this gives me an error. Is there a way to reset "FI" in
this case....

FileInfo FI = new FileInfo(string.Concat(strIadsPath, "\\etc\\",
myDataRow["Name"].ToString(), ".ini"));
if (FI.Exists)
FI.Delete();

Just create a new object:

FI = new FileInfo (....);

However, you could also just use the static methods in the File class.
 
Thanks!

I used the File class in some other areas, where I was doing I/O and not doing deletes.
 
Back
Top