directory listing..loop thru files

  • Thread starter Thread starter Glenn
  • Start date Start date
G

Glenn

Hi,

My question is how to get a directory list? I'm an old C programmer,
and am having trouble finding exactly how to do this on the VC#
Express "How Do I.." help. I found Directories.GetFiles, but there are
no examples of accessing the files in a loop. If someone could give me
an example to work with, I'd appreciate it.

Thanks,
Glenn
 
Hi,

My question is how to get a directory list? I'm an old C programmer,
and am having trouble finding exactly how to do this on the VC#
Express "How Do I.." help. I found Directories.GetFiles, but there are
no examples of accessing the files in a loop. If someone could give me
an example to work with, I'd appreciate it.

Thanks,
Glenn

Here's a slice of code that I use...

string[] Files = Directory.GetFiles((string)MyPath, "*.dat");

foreach (string f in Files)
{
FileInfo FI = new FileInfo(f);
// <SNIP> ... check file info to make sure the .DAT file is bigger
than 1MB, etc.
}
 
Hi,

My question is how to get a directory list? I'm an old C programmer,
and am having trouble finding exactly how to do this on the VC#
Express "How Do I.." help. I found Directories.GetFiles, but there are
no examples of accessing the files in a loop. If someone could give me
an example to work with, I'd appreciate it.

Thanks,
Glenn

Try:

foreach(FileInfo fi in ....)

-mdb
 
Hi,

My question is how to get a directory list? I'm an old C programmer,
and am having trouble finding exactly how to do this on the VC#
Express "How Do I.." help. I found Directories.GetFiles, but there are
no examples of accessing the files in a loop. If someone could give me
an example to work with, I'd appreciate it.

Thanks,
Glenn

Here's a slice of code that I use...

string[] Files = Directory.GetFiles((string)MyPath, "*.dat");

foreach (string f in Files)
{
FileInfo FI = new FileInfo(f);
// <SNIP> ... check file info to make sure the .DAT file is bigger
than 1MB, etc.
}

Excellent..thanks to both of you for responses
 
Hi,

My question is how to get a directory list? I'm an old C programmer,
and am having trouble finding exactly how to do this on the VC#
Express "How Do I.." help. I found Directories.GetFiles, but there are
no examples of accessing the files in a loop. If someone could give me
an example to work with, I'd appreciate it.

Thanks,
Glenn

Directory.GetFiles() will give you an array of the filenames in the
directory
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top