Adding filenames to an array

Get help on programming - C++, Java, Delphi, etc.
Post Reply
Mechano
Registered User
Posts: 291
Joined: 26 Feb 2004, 02:00
Location: Cape Town
Contact:

Adding filenames to an array

Post by Mechano »

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
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

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
Mechano
Registered User
Posts: 291
Joined: 26 Feb 2004, 02:00
Location: Cape Town
Contact:

Post by Mechano »

C#.Net in Visual Studio 2003
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Post by rustypup »

then you already have access to dynamic, typed, collections, as well as all the static sort methods that go with them...

what have you done so far?
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Mechano
Registered User
Posts: 291
Joined: 26 Feb 2004, 02:00
Location: Cape Town
Contact:

Post by Mechano »

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]);
HdB
Registered User
Posts: 929
Joined: 18 Oct 2004, 02:00
Location: Bloemfontein
Contact:

Post by HdB »

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
AMD Athlon 64 X2 4800+ s939 | Gecube 3870 OC edition
Image
Mechano
Registered User
Posts: 291
Joined: 26 Feb 2004, 02:00
Location: Cape Town
Contact:

Post by Mechano »

never mind the indenting...you helped me a lot

the FileInfo[] part was what I needed

Tx :D
Mechano
Registered User
Posts: 291
Joined: 26 Feb 2004, 02:00
Location: Cape Town
Contact:

Another Question

Post by Mechano »

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
HdB
Registered User
Posts: 929
Joined: 18 Oct 2004, 02:00
Location: Bloemfontein
Contact:

Post by HdB »

You'll need a NotifyIcon, and a Context menu. Declared in code, in your case.
AMD Athlon 64 X2 4800+ s939 | Gecube 3870 OC edition
Image
Mechano
Registered User
Posts: 291
Joined: 26 Feb 2004, 02:00
Location: Cape Town
Contact:

Post by Mechano »

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...
Law
Registered User
Posts: 1569
Joined: 12 Sep 2003, 02:00
Location: UND

Post by Law »

what are you opeming the file with?
Mechano
Registered User
Posts: 291
Joined: 26 Feb 2004, 02:00
Location: Cape Town
Contact:

Post by Mechano »

Mechano wrote:
I want to write the contents of a richTextBox to a text file.....
Well, seeing that it's a textfile, with a *.log extension, i'd like to open it with notepad...

Shoul I rather just use a multiline Textbox instead of a richTextBox???
Law
Registered User
Posts: 1569
Joined: 12 Sep 2003, 02:00
Location: UND

Post by Law »

notepad does not support some rich text. try opening it in wordpad and see what happens??
Post Reply