Adding filenames to an array
Adding filenames to an array
I have to create an application that sorts a list of pdf files from oldest to newest.
I can retrieve the info from one file easily, but how will I retrieve it from all the files in a specific directory, so that I can add their LastWriteTimeUTC property to an arraylist so I can sort them??? 8O
I can retrieve the info from one file easily, but how will I retrieve it from all the files in a specific directory, so that I can add their LastWriteTimeUTC property to an arraylist so I can sort them??? 8O
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
language?
do you have access to some form of Collection? if not you will need to:
1) Acquire the total number of files
2) Remove those without .pdf extension
3) initialise an array to the desired length
4) acquire an index into the array
5) loop through the files, adding each into the newly initialised array..
when you get this far we can discuss sorting algorithms.. bubble sort anything below 50 only... thereafter your trade-off in using a quick or quick+insertion sort combination is the better option...
language?
do you have access to some form of Collection? if not you will need to:
1) Acquire the total number of files
2) Remove those without .pdf extension
3) initialise an array to the desired length
4) acquire an index into the array
5) loop through the files, adding each into the newly initialised array..
when you get this far we can discuss sorting algorithms.. bubble sort anything below 50 only... thereafter your trade-off in using a quick or quick+insertion sort combination is the better option...
language?
Most people would sooner die than think; in fact, they do so - Bertrand Russel
I don't know how this is gonna look...
It gives me an error : The given path's format is not supported
string filePath = "C:/pdf/";
ArrayList fileLst = new ArrayList();
Directory fDir;
string [] fFile = Directory.GetFiles(filePath);
int x = 0;
foreach (string DirFile in fFile)
{
FileInfo infoF = new FileInfo(filePath + DirFile.ToString() + ".pdf");
fileLst.Add(infoF.LastWriteTimeUtc);
fileLstBox.Items.Add(x.ToString()+ ". " + fileLst[x]);
x++;
}
MessageBox.Show("Time :" + fileLst[0] + " Time 2 : " + fileLst[1]);
It gives me an error : The given path's format is not supported
string filePath = "C:/pdf/";
ArrayList fileLst = new ArrayList();
Directory fDir;
string [] fFile = Directory.GetFiles(filePath);
int x = 0;
foreach (string DirFile in fFile)
{
FileInfo infoF = new FileInfo(filePath + DirFile.ToString() + ".pdf");
fileLst.Add(infoF.LastWriteTimeUtc);
fileLstBox.Items.Add(x.ToString()+ ". " + fileLst[x]);
x++;
}
MessageBox.Show("Time :" + fileLst[0] + " Time 2 : " + fileLst[1]);
Hi, try this
private void Form1_Load(object sender, System.EventArgs e)
{
DirectoryInfo theDir = new DirectoryInfo("c:\\pdf");
FileInfo[] theFiles = theDir.GetFiles();
int intCount = 0;
if (theFiles.Length > 0)
{
// Do sorting
if (theFiles.Length > 1)
{
FileInfo tmpFile;
int intPass = (theFiles.Length - 1);
bool blnDone = true;
while (intPass >= 0 & blnDone == false)
{
blnDone = true;
for(intCount = 0; intCount <= (intPass - 1); intCount++)
{
if (theFiles[intCount].LastWriteTimeUtc > theFiles[intCount + 1].LastWriteTimeUtc)
{
blnDone = false;
tmpFile = theFiles[intCount + 1];
theFiles[intCount + 1] = theFiles[intCount];
theFiles[intCount] = tmpFile;
}
}
intPass -= 1;
}
}
//Show files
for(intCount = 0; intCount <= (theFiles.Length - 1); intCount++)
{
fileLstBox.Items.Add(intCount.ToString() + " - " + theFiles[intCount].FullName + " : " + theFiles[intCount].LastWriteTimeUtc);
}
}
}
Edit: crap! stupid indenting
private void Form1_Load(object sender, System.EventArgs e)
{
DirectoryInfo theDir = new DirectoryInfo("c:\\pdf");
FileInfo[] theFiles = theDir.GetFiles();
int intCount = 0;
if (theFiles.Length > 0)
{
// Do sorting
if (theFiles.Length > 1)
{
FileInfo tmpFile;
int intPass = (theFiles.Length - 1);
bool blnDone = true;
while (intPass >= 0 & blnDone == false)
{
blnDone = true;
for(intCount = 0; intCount <= (intPass - 1); intCount++)
{
if (theFiles[intCount].LastWriteTimeUtc > theFiles[intCount + 1].LastWriteTimeUtc)
{
blnDone = false;
tmpFile = theFiles[intCount + 1];
theFiles[intCount + 1] = theFiles[intCount];
theFiles[intCount] = tmpFile;
}
}
intPass -= 1;
}
}
//Show files
for(intCount = 0; intCount <= (theFiles.Length - 1); intCount++)
{
fileLstBox.Items.Add(intCount.ToString() + " - " + theFiles[intCount].FullName + " : " + theFiles[intCount].LastWriteTimeUtc);
}
}
}
Edit: crap! stupid indenting
Another Question
I have to forms for this application --- mainForm and configForm
I do not want the configForm to appear in the windows taksbar when I activate it from within the mainForm.
I also want the app to minimize to the system tray when I click minimize
Any help....I'm busy googling
I do not want the configForm to appear in the windows taksbar when I activate it from within the mainForm.
I also want the app to minimize to the system tray when I click minimize
Any help....I'm busy googling
Right, this app is close to finished...
I want to write the contents of a richTextBox to a text file, in exactly the same context as I view it in my app. In other words, where there is a line break, I want it to to be shown in the text file as well
I use this,
StreamWriter wLog = new StreamWriter({file details});
wLog.WriteLine(detailsTxtBox.Text);
wLog.Flush();
wLog.Close();
however, this writes all the lines in my textbox side by side, with a '□' showing where the line breaks should be...any ideas...
I want to write the contents of a richTextBox to a text file, in exactly the same context as I view it in my app. In other words, where there is a line break, I want it to to be shown in the text file as well
I use this,
StreamWriter wLog = new StreamWriter({file details});
wLog.WriteLine(detailsTxtBox.Text);
wLog.Flush();
wLog.Close();
however, this writes all the lines in my textbox side by side, with a '□' showing where the line breaks should be...any ideas...