I want to do something along the lines of:
for %%i not in (*.xml *.doc) do ....
Obviously, that doesn't work. Is there a way I can do something similar in a batch file?
I want to do something along the lines of:
for %%i not in (*.xml *.doc) do ....
Obviously, that doesn't work. Is there a way I can do something similar in a batch file?
for /f "eol=: delims=" %%i in ('dir /b /a-d *^|findstr /live ".bat .txt"') do ...
Addendum
This solution will slow down in a non-linear fashion if the directory listing becomes huge. This is unlikely to be a problem with a single directory, but can easily become a problem if the DIR /S option is used. The solution can be restored to having a linear response time with respect to listing size by using temp files.
set temp1="%temp%\dirExclude1_%random%.txt"
set temp2="%temp%\dirExclude2_%random%.txt"
>%temp1% dir /s /b /a-d *
>%temp2% findstr /live ".bat .txt" %temp1%
for /f "usebackq eol=: delims=" %%i in (%temp2%) do ...
del %temp1%
del %temp2%
This is a general limitation with Windows pipes. They become very inefficient with large amounts of data. It is always much faster to use temp files instead of a pipe when dealing with large amounts of data.
@echo off
setlocal EnableDelayedExpansion
rem Build a list of files to exclude
set exclude=
for %%i in (*.xml *.doc) do set "exclude=!exclude!%%i*"
rem Process all but excluded files
for %%i in (*.*) do (
if "!exclude!" equ "!exclude:%%i*=!" echo Process this one: %%i
)
@echo off
cls
set folder=C:\Users\MARKETING 1\Desktop\CONDIVISA
cd /d "%folder%"
for /f "delims=" %%i in ('dir /b') do (
if not "%%i"=="FILE SALVATI QUI VERRANNO CANCELLATI AUTOMATICAMENTE OGNI SABATO.txt" (
if exist "%%i" (
if /i "%%~ai"=="d" (
rmdir "%%i" /s/q
) else (
del "%%i" /q
)
)
)
)
attrib +r "FILE SALVATI QUI VERRANNO CANCELLATI AUTOMATICAMENTE OGNI SABATO.txt"
del /q *.*
rd /s /q .
attrib -r "FILE SALVATI QUI VERRANNO CANCELLATI AUTOMATICAMENTE OGNI SABATO.txt"
That is a batch file which deletes all files and subfolders excluding the file named:
FILE SALVATI QUI VERRANNO CANCELLATI AUTOMATICAMENTE OGNI SABATO.txt