computing
  • 2

Solved CMD DIR Command Exclude Files In List

  • 2

Hello all,

I want to execute a dir command but exclude some files from the result.

for example in a dir I have:

C:\Folder\a.pdf
C:\Folder\b.exe
C:\Folder\c.csv
C:\Folder\d.ini

also I have a txt file which is located in “C:blacklist.txt” which has this entries:
a.pdf
c.csv

now I want to use something like this:

dir C:\Folder /exclude=C:\blacklist.txt
and the result would look like this:

C:\Folder\b.exe
C:\Folder\d.ini

xcopy has exclude, any chance at dir command?

The Problem is that I will need the listed files excluded on the fly, means I can’t use the method:

dir all files/folders, have them printed into a txt file and then use loop to delete the files in blacklist.txt

Thanks in advance!

Share

1 Answer

  1. ::====== script starts here ===============
    ::
    :: exclude.bat 2013-06-17 12:31:57.35
    @echo off & setLocal enableDELAYedeXpansioN

    :main
    for /f “tokens=* delims= ” %%a in (‘dir/b c:\temp’) do (
    find /i “%%a” < blaklist.txt > nul || echo.%%a
    )
    goto :eof
    ::====== script ends here =================

    =====================
    M2 Golden-Triangle

    • 0