View Full Version : The same batch file does not run on Win 7
XhmikosR
2nd September 2009, 17:04
Hi, everyone. I use the following batch file to encode multiple files:
@ECHO OFF
CLS
SETLOCAL enabledelayedexpansion
CHOICE /C yn /CS /M "Do you want to start the encoding"
IF ERRORLEVEL 2 ECHO.&&GOTO :END
IF ERRORLEVEL 1 ECHO.&&GOTO :startencode
:startencode
CLS
FOR /f %%i IN ('dir /b *.bat') DO (
SET name=%%~ni
CALL "!name!.bat"
ECHO.
ECHO.
)
:END
ENDLOCAL && PAUSE
The above is working fine on Vista. A few days now I moved to Windows 7 and the above script does not run on it. There is something wrong when setting the variable "name". I really cannot see the reason for this to happen.
Thanks in advance!:)
stax76
2nd September 2009, 17:23
Even I never bothered to really learn the batch I think I know is the problem, CHOICE was removed but I'm not 100% sure.
Edit: I thought choice was removed before Vista so it might be another Problem.
XhmikosR
2nd September 2009, 17:27
No, choice is still there. There is something else wrong with setting the variable. But on Vista everything was working fine.
RunningSkittle
2nd September 2009, 19:07
Im not at home, so i cant test anything... but my advice to you when debugging batch scripts:
Place an echo command before stuff and pauses (ie break points) to make sure that it works up to certain points.
FOR /f %%i IN ('dir /b *.bat') DO (
echo SET name=%%~ni
SET name=%%~ni
pause
echo CALL "!name!.bat"
pause
CALL "!name!.bat"
ECHO.
ECHO.
)
also its not really necessary or recommended to use the /f command to parse the dir command. Use the /r command instead (it also has the benefit of being able to recurse through the directory tree!). Do "for /?" for more information!!
If i had to guess though, i would say its something this (although i dont know why it would be):
enabledelayedexpansion
You dont really need to use that anyway...
Scratch that, i just realized this entire script could be executed in one line...
for /r %%a in ("c:/videos/*.bat") do (call "%%a")
XhmikosR
2nd September 2009, 23:46
Thanks for your answer, but still the same. I did found the error, that's why I told you there is something wrong with setting the variable.
For now, I found the following to work as expected:
FORFILES -m *.bat -c "CMD /C CALL @FILE"
But I still don't get it why the previous code works on Vista but not on Windows 7. If you found the cause for this let me know.
RunningSkittle
3rd September 2009, 03:33
what happens if you do this instead:
SET name="%%~ni"
XhmikosR
3rd September 2009, 09:30
Thank you, that was it. :) Although I have not changed the folder or the filenames and they do not contain any spaces. I only changed the OS. Weird...
RunningSkittle
3rd September 2009, 17:33
could you post the final version of this batch file and a sample of the ones that are called? (for my own amusement) :thanks:
XhmikosR
3rd September 2009, 21:20
The working script is that in the first post, except that SET name="%%~ni". It's just a bunch of scripts of Big Buck Bunny, so it wouldn't be of any use unless you have the sources. :)
SenHu
5th October 2009, 17:54
Use biterscripting scripts instead. These scripts work exactly the same way irrespective of the windows version. Some sample scripts are at http://www.biterscripting.com/samples_internet.html .
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.