Tuesday, July 12, 2011

Deleting the backup files in the directory perl

Use simply

unlink(<*.bak>);  
Here i have assumed the backup files to end with .bak this wildcard can be changed as per your requirement
in the perl script and execute it will delete all the files ending up .bak in the current directory


you can also execute from the command line as follows:

G:\perl_programs>perl -e "unlink(<*.bak>);"

2 comments:

  1. Please don't use . Use glob("wildcard"). Much less confusing, much easier to extend.

    $wildcard = "*.bak";
    unlink <$wildcard>;

    That doesn't work as intended. Change to glob, it does.

    ReplyDelete