I need help to rename files in c#.
I have 10 files in one folder. My requirement is I have add date part (MMddyyyyhhmmss) in all 10.
ex :
1_gender_vadra_ram_R4.txt
2_gender_vadra_syam_R4.txt
Now out put would be
1_gender_vadra_ram_R4_MMddyyyyhhmmss.txt
2_gender_vadra_syam_R4_MMddyyyyhhmmss.txt
I have tried below code but failed to get above file names.
varArchiveDataFolder
is variable which value will come from ssis.
varArchiveDataFolder ="D:\Ram\
DirectoryInfo d = new DirectoryInfo(Dts.Variables["varArchiveDataFolder"].Value.ToString());
FileInfo[] infos = d.GetFiles();
foreach(FileInfo f in infos)
{
string CurrDate = System.DateTime.Now.ToString("MM/dd/yyyy HH:mm");
CurrDate = CurrDate.Substring(0, 2) + CurrDate.Substring(3, 2) + CurrDate.Substring(6, 4) + CurrDate.Substring(11, 2) + CurrDate.Substring(14, 2);
File.Move(f.FullName, f.FullName.ToString().Replace("R4","R4_"+ "Currdate"));
}
My actual requirement is I need to delete files from Archive directory, if file is greater than 30 days of today.