From: Dee Earley on
On 22/10/2009 22:57, Scott M. wrote:
> "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.

Deleting a folder requires deleting the contents first, leaving the same
problem.

--
Dee Earley (dee.earley(a)icode.co.uk)
i-Catcher Development Team

iCode Systems
From: Dee Earley on
On 23/10/2009 02:31, Bee wrote:
> "Karl E. Peterson" wrote:
>> DEL *.* /S works pretty darn well, too, fwiw. Lots less effort.
>
> DOS - showing your age?
> (OK me too but why use DOS when you can code and get all the satisfaction!!!)

No one mentioned DOS until you.. :)
Besides, the command is quicker than writing the app, especially if a
customer/boss is peering over your shoulder. If you have the app already
then allbeit.
I don't, a command prompt is more readily to hand.

--
Dee Earley (dee.earley(a)icode.co.uk)
i-Catcher Development Team

iCode Systems
From: Dee Earley on
On 22/10/2009 22:23, 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.

File enumeration is slow, especially on large folders.
You could cache the date info or get the creator to put them in
datestamped folders.

--
Dee Earley (dee.earley(a)icode.co.uk)
i-Catcher Development Team

iCode Systems
From: Eduardo on
Dee Earley escribi�:
> On 22/10/2009 22:57, Scott M. wrote:
>> "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.
>
> Deleting a folder requires deleting the contents first, leaving the same
> problem.
>

He could use SHFileOperation.

http://msdn.microsoft.com/en-us/library/bb762164%28VS.85%29.aspx

"File deletion is recursive unless you set the FOF_NORECURSION flag in
lpFileOp."

I'm not sure if moving the files to a temp folder and deleting the
entire folder with SHFileOperation could speed it up, but I would test it.

SHFileOperation can be used to delete and move individual files also.

http://allapi.mentalis.org/apilist/SHFileOperation.shtml

http://www.thescarms.com/vbasic/fileops.aspx
From: Dee Earley on
On 23/10/2009 14:11, Eduardo wrote:
> Dee Earley escribi�:
>> On 22/10/2009 22:57, Scott M. wrote:
>>> "Saga"<antiSpam(a)nowhere.com> wrote in message
>>> news:%23pCPU31UKHA.4360(a)TK2MSFTNGP04.phx.gbl...
>>> 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.
>>
>> Deleting a folder requires deleting the contents first, leaving the
>> same problem.
>
> He could use SHFileOperation.
>
> http://msdn.microsoft.com/en-us/library/bb762164%28VS.85%29.aspx
>
> "File deletion is recursive unless you set the FOF_NORECURSION flag in
> lpFileOp."

I was talking about the base file operation (in fat/ntfs).
SHFileOperation() does essentially the same by deleting all the files
individually followed by the folder.

--
Dee Earley (dee.earley(a)icode.co.uk)
i-Catcher Development Team

iCode Systems