I need to rename multiple CSV file names. I want to remove everything after the "-" so for example "File-1.csv" will become just "File.csv". Here's my code that's not working:
DirectoryInfo d = new DirectoryInfo(@"C:\folder");
FileInfo[] infos = d.GetFiles();
foreach (FileInfo f in infos)
{
File.Move(f.FullName, f.FullName.ToString().Substring(0, f.LastIndexOf('-')));
}
I'm getting this error:
Error 2 'System.IO.FileInfo' does not contain a definition for 'LastIndexOf' and no extension method 'LastIndexOf' accepting a first argument of type 'System.IO.FileInfo' could be found (are you missing a using directive or an assembly reference?)
How can I fix this?
LastIndexOf()on aSystem.IO.FileInfo. Is that what you meant to do? Did you look for that method in the documentation forSystem.IO.FileInfo?