Link to home
Start Free TrialLog in
Avatar of babybird
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(strCommissionsPath);
                               
                if (file.Exists)
                {
                    string strBakFileName = strCommissionsPath;

                    strBakFileName = strBakFileName.Insert(strBakFileName.IndexOf(".csv"), intCounter.ToString());
                    strBakFileName = strBakFileName.Replace(".csv", ".bak");
                    file = FileInfo(strBakFileName);

                    if (file.Exists)
                    {
                        intCounter = intCounter + 1;
                    }

Thanks so much for your help!
                }
SOLUTION
Avatar of Justin_W
Justin_W

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Justin_W
Justin_W

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.
Avatar of babybird

ASKER

I didn't know that was an option...

thanks to all for your help!!!