Delete .bak files with Right Click (windows)

Delete .bak files with Right Click (windows)

1
NewbieNewbie
1

    Jul 28, 2005#1

    I got sick of deleting all my .bak files manually when I was done with a project, so I wrote a quick php script to do a batch job. I added an menu option for right click on folders. probably could be cleaner, but thought I share with the forum for anyone else who might be interested.

    requirements:
    * Windows
    * php installed
    * a bunch of unwanted .bak files

    installation:

    1) copy this script to a file and save it somewhere useful (referenced as C:/path/to/cleanBakFiles.php) - don't forget to wrap it in <?php ?>.

    Code: Select all

    if($argc != 2){
      echo "no dice - need a folder name";
    }
    else{
      f_delete_bak_files($argv[1]);
    }
    function f_delete_bak_files($dir){
      if(is_dir($dir)){
        if($dh = opendir($dir)){
          while(($file = readdir($dh)) !== false) {
            if(is_dir($dir ."/". $file) && $file != "." && $file != ".."){
              f_delete_bak_files($dir ."/" . $file);
            }
            if(ereg(".bak$", $file) || ereg(".BAK$", $file)){
              unlink($dir . "/" . $file);
              echo("DEL - " . $dir . "/" . $file . "\n");
            }
          }
          return true;
        }
      }
      else{
        return false;
      }
    }
    2) open an explorer window and go to Tools > Folder Options

    3) on the File Types tab, select Folder and click Advanced

    4) click New...
       Action: Clean .bak Files
       Application used to perform action: C:\path\to\php.exe C:/path/to/cleanBakFiles.php "%1"

    5) try it out.

    Hope this helps someone out. There is a way to set the right click action with regedit, post if you need a hand with that.

    6,686585
    Grand MasterGrand Master
    6,686585

      Jul 28, 2005#2

      Tip: At the Backup tab of the configuration dialog a Default Backup Directory can be specified. Setting this and all your .bak files are created in 1 directory and do not spread anymore over all your project directories.
      Best regards from an UC/UE/UES for Windows user from Austria