From: Saga on
Hi All,

I have a routine that deletes files that are older than X days. I get the
file names into an array then I for each filename I determine if it is older
than X days and if it is I delete it. I use the Dir$() and Kill functions
for this. It works as expected when there are few files in the folder, but
takes a loooong time when there are tens of thousand of files.

My peeve is that I need to check the age of the file and delete it only if
it older than the number of specified days. I searched for different
routines, but none of them illustrate what I need to do. Does any one have
any suggestions on an alternative, faster way to do this? Thanks! Saga

PS: I will follow up on Monday.


From: Bob Butler on

"Saga" <antiSpam(a)nowhere.com> wrote in message
news:%23pCPU31UKHA.4360(a)TK2MSFTNGP04.phx.gbl...
> Hi All,
>
> I have a routine that deletes files that are older than X days. I get the
> file names into an array then I for each filename I determine if it is
> older than X days and if it is I delete it. I use the Dir$() and Kill
> functions for this. It works as expected when there are few files in the
> folder, but takes a loooong time when there are tens of thousand of files.
>
> My peeve is that I need to check the age of the file and delete it only if
> it older than the number of specified days. I searched for different
> routines, but none of them illustrate what I need to do. Does any one have
> any suggestions on an alternative, faster way to do this? Thanks! Saga

I don't know if it'd help much but if you use
FindFirstFile/FindNextFile/FindClose instead of Dir$ you'll get the modified
date along with the filename.

Can the files be re-organized into sub folders in some way? If not then
processing "tens of thousands" is probably always going to take a while.


From: Scott M. on

"Saga" <antiSpam(a)nowhere.com> wrote in message
news:%23pCPU31UKHA.4360(a)TK2MSFTNGP04.phx.gbl...
> Hi All,
>
> I have a routine that deletes files that are older than X days. I get the
> file names into an array then I for each filename I determine if it is
> older than X days and if it is I delete it. I use the Dir$() and Kill
> functions for this. It works as expected when there are few files in the
> folder, but takes a loooong time when there are tens of thousand of files.
>
> My peeve is that I need to check the age of the file and delete it only if
> it older than the number of specified days. I searched for different
> routines, but none of them illustrate what I need to do. Does any one have
> any suggestions on an alternative, faster way to do this? Thanks! Saga
>
> PS: I will follow up on Monday.

Just wondering if moving the files to be deleted into a temp folder and then
deleting the folder would be faster than deleting thousands of files. When
a file is delteted, it's really just marked as deletable. Doing it to a
folder once may be faster than doing it to thousands of files.

-Scott


From: Nobody on
Search this site for FindFirstFile. The site is for VB6 and lower despite
its name:

http://vbnet.mvps.org


From: Karl E. Peterson on
Saga wrote:
> Hi All,
>
> I have a routine that deletes files that are older than X days. I get the
> file names into an array then I for each filename I determine if it is older
> than X days and if it is I delete it. I use the Dir$() and Kill functions
> for this. It works as expected when there are few files in the folder, but
> takes a loooong time when there are tens of thousand of files.

I'd break the problem into two (or more) parts. You need to find the bottleneck.
Is it the Dir() loop? Looking up the date stamps? Killing the files?
--
..NET: It's About Trust!
http://vfred.mvps.org