Simple batch scrip help

Discussion in 'other software & services' started by amarildojr, May 30, 2016.

  1. amarildojr

    amarildojr Registered Member

    Joined:
    Aug 8, 2013
    Posts:
    1,977
    Location:
    Brasil
    I need help to create a simple batch script to delete some files on a specific folder and it's sub-folders too.

    What I need it to do:

    • Go to a folder;
    • In this folder, there are two folders. The script needs to search for dozens of terms, then delete ALL files that match the terms.
    On Linux, the script would be similar to this:

    Code:
    find /home/amarildo \( -name "file1*" -o -name "file2*" -o -name "file3*" \) -print -delete
    If it makes any difference, this script is intended for Windows 7.

    Thanks in advance ;)
     
  2. Minimalist

    Minimalist Registered Member

    Joined:
    Jan 6, 2014
    Posts:
    5,060
    You can use:
    Code:
    del "file1" "file2" "file3" /s >> d:\result.txt
    It will erase files and store results in txt file. You can also use wildcards for filenames(*, ?).
     
    Last edited: May 30, 2016
  3. amarildojr

    amarildojr Registered Member

    Joined:
    Aug 8, 2013
    Posts:
    1,977
    Location:
    Brasil
    Wait. How will the script know where to look?
     
  4. MisterB

    MisterB Registered Member

    Joined:
    May 31, 2013
    Posts:
    1,103
    Location:
    Southern Rocky Mountains USA
    The script can just change to the folders and then delete with wildcards. My batch scripting abilities are pretty basic but it would be something like this.

    Code:
    "cd Folder1
    del File1*.*, File2*.*
    cd..
    cd Folder2"
    del File1*.*, File2*.*"
     
  5. Minimalist

    Minimalist Registered Member

    Joined:
    Jan 6, 2014
    Posts:
    5,060
    It should be run from parent directory. With /s switch it will check all subdirs for specified files and delete them, like MisterB explained. If there are more subdir levels in directory structure it will check them all.
     
  6. MisterB

    MisterB Registered Member

    Joined:
    May 31, 2013
    Posts:
    1,103
    Location:
    Southern Rocky Mountains USA
    My windows scripting is pretty basic. I wasn't aware of the /s switch which is just about the same as the /r switch in Linux. Much simpler than changing directories manually.
     
  7. amarildojr

    amarildojr Registered Member

    Joined:
    Aug 8, 2013
    Posts:
    1,977
    Location:
    Brasil
  8. Minimalist

    Minimalist Registered Member

    Joined:
    Jan 6, 2014
    Posts:
    5,060
    You're welcome. :)
     
Loading...