babybird
asked on
reuse instance - can't get format correct
This is likely a silly question but I can't seem to figure out the format....
I am creating a FileInfo instance that I want to reuse in a loop...changing the file that I'm looking for information on. I did not want to create a new instance for every file. This is what I have so far.....I don't have my loop created but don't worry about that.... I'll get to that... the problem is the line: file = FileInfo(strBakFileName); Basically, I'm trying to reuse instance of file and set it to a new file name and then do a file.Exists on the new file name. I've tried file = (FileInfo)strBakFileName and that does work....
FileInfo file = new FileInfo(strCommissionsPat h);
if (file.Exists)
{
string strBakFileName = strCommissionsPath;
strBakFileName = strBakFileName.Insert(strB akFileName .IndexOf(" .csv"), intCounter.ToString());
strBakFileName = strBakFileName.Replace(".c sv", ".bak");
file = FileInfo(strBakFileName);
if (file.Exists)
{
intCounter = intCounter + 1;
}
Thanks so much for your help!
}
I am creating a FileInfo instance that I want to reuse in a loop...changing the file that I'm looking for information on. I did not want to create a new instance for every file. This is what I have so far.....I don't have my loop created but don't worry about that.... I'll get to that... the problem is the line: file = FileInfo(strBakFileName); Basically, I'm trying to reuse instance of file and set it to a new file name and then do a file.Exists on the new file name. I've tried file = (FileInfo)strBakFileName and that does work....
FileInfo file = new FileInfo(strCommissionsPat
if (file.Exists)
{
string strBakFileName = strCommissionsPath;
strBakFileName = strBakFileName.Insert(strB
strBakFileName = strBakFileName.Replace(".c
file = FileInfo(strBakFileName);
if (file.Exists)
{
intCounter = intCounter + 1;
}
Thanks so much for your help!
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The only way to specify which file the FileInfo is associated with is via the constructor, so you can't "reload" the object after it is created.
ASKER
I didn't know that was an option...
thanks to all for your help!!!
thanks to all for your help!!!