This is a sample code that allows me to delete all folders with the name ".RemoveAsap" attached to them
@echo on
set dir="\\TestPC2\c$\Users"
FOR /D /R %dir% %%X IN (*.RemoveAsap) DO RMDIR /S /Q "%%X"
pause
exit
Simply running the code as is runs perfectly but when I try to make the code more interactive, I get the error
@echo on
cd C:\Users\User1\Desktop\Test\
TYPE con >> LowDASD.txt
For /F %%A in (LowDASD.txt) do echo "\\%%A\c$\users\" >> LowDASD2.txt
set "LwDs"="LowDASD2.txt"
FOR /D /R "%LwDs%" %%X IN (*.RemoveAsap) DO RMDIR /S /Q "%%X"
pause
LowDASD2.txt would be the address/ directory location where the directories will be deleted, IE \\TestPC2\c$\Users
The code does not delete anything or give an error that "the path is too long" at least it was doing that with the previous variations that I was trying. If someone can help me with this, i would greatly appreciate it.
Simply will not work, as
%LwDs%is a filename.You would think might work -
%%jbeing assigned to each entry in the%LwDs%file in turn;usebackqused because the filename is "quoted" (seefor /?from the prompt for documentation)But it doesn't - the
for /d /rsyntax doesn't accept metavariables...So - try
Where
expungeis an internal subroutine. The colon is requiredAn internal subroutine should be placed after an unconditional
goto, which should in your case follow thepauseWhere
:eof(compulsory colon again) is defined as the physical end-of-file and should not be used as a user-label. Reaching physical end-of-file returns from acall.Always verify against a test directory before applying to real data.
Note that the
rmdiris merely beingechoed for testing purposes - remove theechokeyword after testing to activate.=== Extension
The full code should thus be