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

  • Thread starter Thread starter MSDN
  • Start date Start date
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
 
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
|
|
|
|
 
Back
Top