How to get only the first file in a directoy without reading the entire directory file collection fi

M

MSDN

Hello,

I have the following code below that does not work for me because the
directory has millions of files.

foreach (string ofile in System.IO.Directory.GetFiles(strMyDir))

{

System.IO.FileInfo oFI = new System.IO.FileInfo(ofile);

oFI.Delete();

}

How can I get the first file and delete it then go back and get the first
file and delete it and repeat....

My system crashes because System.IO.Directory.GetFiles(strMyDir)) has to
ready 100 million files first.

Any ideas

thanks



SA
 
W

Willy Denoyette [MVP]

Delete all files from the command line. You don't create/delete 100 millions
of files in a real world application do you?


Willy.

| Hello,
|
| I have the following code below that does not work for me because the
| directory has millions of files.
|
| foreach (string ofile in System.IO.Directory.GetFiles(strMyDir))
|
| {
|
| System.IO.FileInfo oFI = new System.IO.FileInfo(ofile);
|
| oFI.Delete();
|
| }
|
| How can I get the first file and delete it then go back and get the first
| file and delete it and repeat....
|
| My system crashes because System.IO.Directory.GetFiles(strMyDir)) has to
| ready 100 million files first.
|
| Any ideas
|
| thanks
|
|
|
| SA
|
|
|
|
 

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

Top