Page 1 of 1
DEL / RD: The system cannot find the file specified
Posted: 03 Apr 2012 07:17
by tinfanide
C:\>DIR /B /S "C:\test\New folder"
C:\test\New folder\folder1
C:\test\New folder\folder1\good
C:\test\New folder\folder1\txt.txt
C:\test\New folder\folder1\good\txt.txt
C:\>test\test.bat
Deleted file - C:\test\New folder\folder1\txt.txt
Deleted file - C:\test\New folder\folder1\good\txt.txt
The system cannot find the file specified.
The system cannot find the path specified.
The system cannot find the file specified.
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.
Press any key to continue . . .
C:\>DIR /B /S "C:\test\New folder"
C:\>
Code: Select all
@ECHO OFF
FOR /F "delims=" %%A IN ('DIR /B /S "C:\test\New folder\*"') DO (
DEL /S /Q "%%~fA"
RD /S /Q "%%~fA"
)
PAUSE
What are "The system cannot find the file specified." here referring to?
The codes do what I want (as demonstrated above - delete all the directories and files / subdirectories except the root folder itself).
But how could I get rid of those error lines?
Re: DEL / RD: The system cannot find the file specified
Posted: 03 Apr 2012 07:49
by foxidrive
Take out the /s
Re: DEL / RD: The system cannot find the file specified
Posted: 03 Apr 2012 07:52
by foxidrive
Try this: (untested)
Code: Select all
@ECHO OFF
pushd "C:\test\New folder\" && (
FOR /F "delims=" %%A IN ('DIR /A:D /B') DO RD /S /Q "%%~fA"
FOR /F "delims=" %%A IN ('DIR /A:-D /B') DO DEL /S /Q "%%~fA"
)
popd
PAUSE
Re: DEL / RD: The system cannot find the file specified
Posted: 03 Apr 2012 07:54
by foxidrive
Or this: (untested)
Code: Select all
@ECHO OFF
pushd "C:\test\New folder\" && (
RD /S /Q "C:\test\New folder\" 2>nul
)
popd
PAUSE
Re: DEL / RD: The system cannot find the file specified
Posted: 03 Apr 2012 08:41
by tinfanide
foxidrive wrote:Or this: (untested)
Code: Select all
@ECHO OFF
pushd "C:\test\New folder\" && (
RD /S /Q "C:\test\New folder\" 2>nul
)
popd
PAUSE
I've got most of it.
But one thing not sure...
2>nul (no redirection?) the nul device?
Why is it needed after RD?
Re: DEL / RD: The system cannot find the file specified
Posted: 03 Apr 2012 18:10
by foxidrive
The code will generate an error because the top level folder can't be deleted, and 2>nul removes the harmless error message from the screen.
Re: DEL / RD: The system cannot find the file specified
Posted: 03 Apr 2012 21:13
by tinfanide
foxidrive wrote:The code will generate an error because the top level folder can't be deleted, and 2>nul removes the harmless error message from the screen.
The process cannot access the file because it is being used by another process.
Press any key to continue . . .
Yes, it seems that RD cannot process the top level folder because we PUSHD the top level folder?
Re: DEL / RD: The system cannot find the file specified
Posted: 04 Apr 2012 00:23
by foxidrive
Yup. This all assumes you didn't want to remove the top level folder.