delete old file from specific folder

Discuss and share scripts and script files...
Post Reply
lian00
Posts: 354
Joined: 09 Jul 2014 17:12

delete old file from specific folder

Post by lian00 »

Hello, I need a script to delete files older than 3 monthes from a specific folder (different folders). I suppose it' relatively simple but it will take me hours to find how to manage this so I prefer to ask first.
Thanks for any help.
Windows 10 64 bits

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: delete old file from specific folder

Post by highend »

This one works recursively. If you don't want that, use /fn instead of just /f.

Code: Select all

    $folders = <<<>>>
D:\Users\Name1
D:\Temp
<another folder...>
>>>;

    foreach($folder, $folders, <crlf>, "e") {
        if (exists($folder) != 2) { continue; }
        delete 1, 0, quicksearch("ageC: > 3 m /f", $folder , "|");
    }
One of my scripts helped you out? Please donate via Paypal

lian00
Posts: 354
Joined: 09 Jul 2014 17:12

Re: delete old file from specific folder

Post by lian00 »

Thanks a lot. I must admit I may have succeed but it would not be so efficient.

Code: Select all

$folders = <<<>>>
D:\Users\Name1
D:\Temp
<another folder...>
>>>;
is surprising to me.
Windows 10 64 bits

lian00
Posts: 354
Joined: 09 Jul 2014 17:12

Re: delete old file from specific folder

Post by lian00 »

Hello, I try to delete only .eml files from a directory and it does not seem to work

Code: Select all

  foreach($folder, $folders, <crlf>, "e") {
        if (exists($folder) != 2) { continue; }
        delete 1, 0, quicksearch("ageC: > 3 m AND *.eml /fr", $folder , "|");
    }
Windows 10 64 bits

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: delete old file from specific folder

Post by highend »

You need to use

Code: Select all

delete 1, 0, quicksearch("ageC: > 3 m AND name:*.eml /fr", $folder , "|");
otherwise *.eml is interpreted as ageC:*.eml and not as name:*.eml

The first ageC is so called "propagated" to every other pattern behind it,
until name: is used here
One of my scripts helped you out? Please donate via Paypal

lian00
Posts: 354
Joined: 09 Jul 2014 17:12

Re: delete old file from specific folder

Post by lian00 »

highend wrote:You need to use

Code: Select all

delete 1, 0, quicksearch("ageC: > 3 m AND name:*.eml /fr", $folder , "|");
otherwise *.eml is interpreted as ageC:*.eml and not as name:*.eml

The first ageC is so called "propagated" to every other pattern behind it,
until name: is used here
Thanks. I suspected somethihg like this but the example in documentation did not show name:
Windows 10 64 bits

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: delete old file from specific folder

Post by highend »

Look into
Main Topics - Info Panel - Find Files Tab
under
Field Type Inheritance

There you can find that explanation of propagated types
One of my scripts helped you out? Please donate via Paypal

lian00
Posts: 354
Joined: 09 Jul 2014 17:12

Re: delete old file from specific folder

Post by lian00 »

highend wrote:Look into
Main Topics - Info Panel - Find Files Tab
under
Field Type Inheritance

There you can find that explanation of propagated types
Thanks for the information.
Windows 10 64 bits

Post Reply