When fiddling around a bit, I made this interesting/confusing discovery. As I don't really know how to perform an accurate batch file command time measurement, at least not in the same file, (but I'd appreciate any help with how to do that too), I only have my personal observations, but it is quite noticeable that when I use a dot, ., in my code, that it runs faster. I can see the enter prompt at around half to one second faster than when I use any other normal single latin ASCII character, e.g. a, R, z etc.
vw-xyz.bat
@echo off
setlocal EnableExtensions
setlocal EnableDelayedExpansion
Title xyz
set "arg1=%~1"
if "%arg1%"=="R" goto DIRECT
if not exist "!USERPROFILE!\Desktop\temp\" (
mkdir "!USERPROFILE!\Desktop\temp\"
attrib +h "!USERPROFILE!\Desktop\temp"
!SystemRoot!\System32\xcopy.exe "temp-xyz.bat" "!USERPROFILE!\Desktop\temp\" >nul 2>nul
)
for /r %%a in (*.pdf) do (
!SystemRoot!\System32\xcopy.exe "%%a" "!USERPROFILE!\Desktop\temp\" /D /I /Y /Z >nul 2>nul
)
:DIRECT
(
cls
set /p UserInput=enter xyz: ..
!SystemRoot!\System32\ping.exe -n 1 xyzServer >nul 2>nul
IF !ERRORLEVEL! NEQ 0 (start "" "!USERPROFILE!\Desktop\temp\temp-xyz.bat" & EXIT /B) else (break)
)
!SystemRoot!\System32\taskkill.exe /F /IM "msedge.exe" >nul 2>nul
!SystemRoot!\System32\timeout.exe /T 1 /NOBREAK >nul 2>nul
IF /I "!UserInput!"=="update" (goto UPDATE) else (goto NORMAL)
:UPDATE
!SystemRoot!\System32\ping.exe -n 1 xyzServer | !SystemRoot!\System32\findstr.exe /r /c:"[0-9] *ms"
rmdir /s /q !USERPROFILE!\Desktop\temp >nul 2>nul
(goto) 2>nul & call vw-xyz.bat
:NORMAL
if exist "!USERPROFILE!\Desktop\temp\!UserInput!.pdf" (goto PDF1)
if exist "!USERPROFILE!\Desktop\temp\000000!UserInputID!.pdf" (goto PDF2)
if exist "!USERPROFILE!\Desktop\temp\000000-!UserInputID!.pdf" (goto PDF3) else (goto elsePDF)
:PDF1
start "" /MAX "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" -inprivate file:///"!USERPROFILE!\Desktop\temp\!UserInput!.pdf"
goto RESUME
:PDF2
start "" /MAX "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" -inprivate file:///"!USERPROFILE!\Desktop\temp\000000!UserInput!.pdf"
goto RESUME
:PDF3
start "" /MAX "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" -inprivate file:///"!USERPROFILE!\Desktop\temp\000000-!UserInput!.pdf"
goto RESUME
:elsePDF
start "" "!USERPROFILE!\Desktop\temp\!UserInputID!" >nul 2>nul
goto RESUME
:RESUME
IF !ERRORLEVEL! EQU 0 (break) else (goto DIRECT)
cls
!SystemRoot!\System32\timeout.exe /T 4 /NOBREAK >nul 2>nul
(goto) 2>nul & start "" vw-xyz.bat "R"
This program is used to open PDF files, which are normally centrally stored on a working PC, by entering their 'name'.
I know that the half second, or so, doesn't really do anything to make or break it, but I'm still curious as in how can this be? Shouldn't all single ASCII letters be about the same speed in a == string comparison?
*Update: Tried it at home and here to my surprise the (goto) 2>nul & part stopped working all together. Exit /B didn't work as well. Only a Exit in the next line seems to work. what?? Also the performance difference isn't there anymore or it is that small that I cannot see it visually. And to add to my absolute confusion now: When at work :elsePDF tries to open a file but obviously cant find a file without file extension in a newly created folder and through such prompts you with an error message; at home it opens the 'temp' folder in windows explorer. ???? How can two Win10 Machines with version 21H1 differ in how cmd/bat files are executed?