Reputation: 13
I am trying to create a batch script to move a set of files from one folder (root) to another and delete files of extension .dll
in the root folder except one file. The command I tried is able to copy but not delete the files.
MOVE D:\mpgdata\sync\*.txt D:\data\sync\QDB_TXT_FILES
for %%i in (d:\data\sync*.dll) do if not "%%i"=="work.dll" del /f "%%i"
Upvotes: 1
Views: 3023
Reputation: 41234
It had a case sensitive compare. /i
fixes that.
There was also a missing backslash.
The %%~nxi
makes it compare the filename only.
MOVE "D:\mpgdata\sync\*.txt" "D:\data\sync\QDB_TXT_FILES"
dir d:\data\sync\*.dll /b
pause
for %%i in (d:\data\sync\*.dll) do if /i not "%%~nxi"=="work.dll" del "%%i"
Upvotes: 3