Search code examples
listbatch-filedirectorydir

Batch script to list folders but exclude specific folders


I want this script to list all folders that contains "deleted" in the folder name but not if they is in a folder called "done".

For exampel: list the folder if it's in C:\temp and if it's in C:\temp\random_folder_name but not not if it's in C:\temp\done

dir /s "C:\temp" | findstr "\deleted"

short story, exclude all folders named "done" and their content.


Solution

  • You are almost there.

    Findstr /v returns all lines, that do not contain the string

    dir /ad will only show directories (Atrribut=Directory)

    dir /s /ad "C:\temp" | findstr "\deleted" | findstr /v "\done"