FileNotFound exception when trying to move a file using File.Move
I have a folder with more than 2000+ MS Excel 2010.XLSX and I need to follow these steps:
-
I need to open every single file
-
Copy the content of cell B4 (+ each file has unique content in cell B4) and
-
add content of cell B4 to original file name
How can I fix this error to successfully rename my tables as above?
//file rename code
DirectoryInfo d = new DirectoryInfo(@"C:\Torename\");
FileInfo[] infos = d.GetFiles();
foreach (FileInfo f in infos)
{
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
Workbook wb = excel.Workbooks.Open(f.FullName);
Worksheet excelSheet = wb.ActiveSheet;
//Read the first cell
string test = excelSheet.Cells[4, 2].Value.ToString();
File.Move(f.Name, new_filename);
***Thank you for your assistance that did the trick
+3
source to share