Projects Log

projects, diy

Search:

« PreviousNext »

How to delete file older than X days with Perl and WMI

9 July 2006

Original idea: Microsoft Scripting Guys (link)

Ok, that's not that hard, some VBScript to Perl translation, a little modification and that's all!

I think it should work works remotely too (untested yet) by changing $strComputer with the targeted computer (you need some specific credentials).

my $strComputer = ".";
"." means local computer

my $maxage=15;
every file older than 15 days in $folder will be deleted

my $folder="c:\\temp";
change this with the folder you want to check (WARNING: be careful to prevent unwanted file from being deleted, and do not forget to escape \ character everywhere)

[edited: July 10, 2006  11:00 pm => scan subfolders recursively;
uncomment #$_->Delete; after some tests to realy delete files]

[The requested file http://dev.pulsed.net/wp/code/delete.pl could not be found]

Archived in perl, win32, wmi | Trackback | del.icio.us | Top Of Page

2 Responses to “How to delete file older than X days with Perl and WMI”

  1. SCiPS Says:

    pour le code dans wordpress j'ai un plug-in:

    http://elasticdog.com/2004/09/code-viewer/

    mais il n'est pas bien supporté par l'éditeur wysiwyg il faut donc éditer en mode html pure sous wordpress.

    les tags à utiliser sont:
    <viewcode src="/coderepository/myproject/mycode.pl" link="yes">

    bat.

    Seb.

  2. Kevin Says:

    Merci beaucoup!
    le resultat était quelque peu bizarre cela dit, toutefois apres quelques modifications j'arrive au même resultat que j'avais avant, mais en 1000 fois plus simple!

    Encore merci!