EvilAlchemist
2[H]4U
- Joined
- Jan 11, 2008
- Messages
- 2,730
Been trying to research this but not coming up with many answers on my own:
Have a small application that pulls the pdf files from a directory and shows them in a listbox.
All of the file names "should" be 8 Characters long + file extension.
Lately, the personal saving the pdf files are adding extra things into the name.
Correct Name: 15001123.pdf
What is Happening: 15001231 10/2 Johnny Report.pdf
It makes the listbox look tacky and just kinda irks me i have to keep asking ppl to stop.
So, I want to make a string to loop threw the directory and rename the files basically after 8 characters to "chop off" all the extra they add on ..
Any suggestions ?
Here is my code that pulls the files for the listbox and deletes older files.
(Just so you can see i do have a working program and not a random question)
Have a small application that pulls the pdf files from a directory and shows them in a listbox.
All of the file names "should" be 8 Characters long + file extension.
Lately, the personal saving the pdf files are adding extra things into the name.
Correct Name: 15001123.pdf
What is Happening: 15001231 10/2 Johnny Report.pdf
It makes the listbox look tacky and just kinda irks me i have to keep asking ppl to stop.
So, I want to make a string to loop threw the directory and rename the files basically after 8 characters to "chop off" all the extra they add on ..
Any suggestions ?
Here is my code that pulls the files for the listbox and deletes older files.
(Just so you can see i do have a working program and not a random question)
Code:
InitializeComponent();
DirectoryInfo dinfo = new DirectoryInfo("\\\\SERVER\\Forms\\CAD Reports");
FileInfo[] Files = dinfo.GetFiles("*.pdf");
var orderedFiles = Files
.OrderByDescending(d => d.CreationTime)
.Take(20);
foreach (FileInfo file in orderedFiles)
{
CADList.Items.Add(Path.GetFileNameWithoutExtension(file.Name));
}
string[] oldfiles = Directory.GetFiles("\\\\SERVER\\Forms\\CAD Reports");
foreach (string file in oldfiles)
{
FileInfo fi = new FileInfo(file);
if (fi.CreationTime < DateTime.Now.AddDays(-14))
fi.Delete();
}