You are not logged in.
Pages: 1
Hello.
I have the following script, used as temp file cleaner:
call :rc %localappdata%\Temp
call :rc "D:\temp test\"
exit /b 0
:rc
cd /d "%~1"
if /i "%cd%" neq "%~1" goto :eof
del *.* /s /q /f
goto :eof
The idea is to make universal, used path with and without spaces in it. Once the function :rc is called, I'd like to make sure the path is changed before any deletion occurs. Is there a better way to do this, other that what I've wrriten?
Thank you
Last edited by Eehixohw (20 Aug 2016 15:33)
Offline
You may use the fact that CD command returns an ERRORLEVEL of 1 when the current directory was not changed:
cd /d "%~1"
if errorlevel 1 goto :eof
You may review further details on this point at the Table 2 of this answer.
Antonio
Offline
You may use the fact that CD command returns an ERRORLEVEL of 1 when the current directory was not changed:
cd /d "%~1" if errorlevel 1 goto :eof
You may review further details on this point at the Table 2 of this answer.
Antonio
Could you take it further and say
cd /d "%~1"||goto :eof
Offline
Both suggestions work great.
Thank you guys.
Offline
Pages: 1