Search code examples
c#fileinfo

C# Change current FileInfo file?


I'd like to change the file that the FileInfo object is currently using. Let say I want to loop through 1000 files.

FileInfo myFile = new FileInfo("myfile.txt");

myFile.ChangeFile("myfile2.txt");

How can I do this? Was hoping for .FileName =, but it's readonly.


Solution

  • You cannot do that. The file name is specified at construction and cannot be changed later.