Reading Directory Information

  • Thread starter Thread starter Greg Smith
  • Start date Start date
G

Greg Smith

Hi, all.

I have been asked to write an application that would keep track on archive
data on CDs and DVDs. I will basically need a line for each file.

I have started out by saving a "dir" to a text file and parsing the file,
but it seems there must be a better way to do this.

Is there a way to read down a directory tree and get all the folder and file
information?


Any help is greatly appreciated.
 
U¿ytkownik "Greg Smith said:
Hi, all.

I have been asked to write an application that would keep track on archive
data on CDs and DVDs. I will basically need a line for each file.

I have started out by saving a "dir" to a text file and parsing the file,
but it seems there must be a better way to do this.

Is there a way to read down a directory tree and get all the folder and
file information?
If you want to scan disk recursive, you can use that code:
---
public void ProcessDir(string sourceDir, int recursionLvl)
{
string [] fileEntries = Directory.GetFiles(sourceDir);
foreach(string fileName in fileEntries)
fileList.Items.Add (fileName ,CheckState.Checked);

string [] subdirEntries = Directory.GetDirectories(sourceDir);
foreach(string subdir in subdirEntries)
if ((File.GetAttributes(subdir) &
FileAttributes.ReparsePoint)!=FileAttributes.ReparsePoint)
ProcessDir(subdir,recursionLvl+1);
}
---
this works with checkbox list, but of course you can change it, and save to
xml or sth.


Inez Korczyñski
 
Exactly what I needed.

Thanks a million.

Inez Korczynski said:
U¿ytkownik "Greg Smith said:
Hi, all.

I have been asked to write an application that would keep track on
archive data on CDs and DVDs. I will basically need a line for each
file.

I have started out by saving a "dir" to a text file and parsing the file,
but it seems there must be a better way to do this.

Is there a way to read down a directory tree and get all the folder and
file information?
If you want to scan disk recursive, you can use that code:
---
public void ProcessDir(string sourceDir, int recursionLvl)
{
string [] fileEntries = Directory.GetFiles(sourceDir);
foreach(string fileName in fileEntries)
fileList.Items.Add (fileName ,CheckState.Checked);

string [] subdirEntries = Directory.GetDirectories(sourceDir);
foreach(string subdir in subdirEntries)
if ((File.GetAttributes(subdir) &
FileAttributes.ReparsePoint)!=FileAttributes.ReparsePoint)
ProcessDir(subdir,recursionLvl+1);
}
---
this works with checkbox list, but of course you can change it, and save
to xml or sth.


Inez Korczyñski
 
Back
Top