As a supplement to my earlier comments, (which should solve your reported issue), here's an alternative methodology:
@Echo Off
Verify 1 2> NUL
SetLocal EnableExtensions
If ErrorLevel 1 (Echo ERROR: Could not enable extensions.
GoTo PressClose)
If "%~1" == "" (Echo ERROR: No input argument received.
GoTo InputError) Else For %%G In ("%~1") Do If "%%~aG" Lss "d" (
If "%%~aG" GEq "-" (Echo ERROR: Input argument is a file.
GoTo InputError
) Else (Echo ERROR: Your input argument could not be found.
GoTo InputError))
Rem === Your code here ===
CD /D %1
Set /P "=Your current directory is: %CD%" 0< NUL & Echo(
Rem === Code ends here ===
GoTo PressClose
:InputError
Echo This script requires an existing directory as input.
:PressClose
Echo Please press a key to exit this script.
Pause 1> NUL
Exit /B
You would obviously just insert your code in between the two Rem
arks, I've included two lines there, for the purpose of showing you that it worked, you are of course free to adjust those as necessary
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…