Little help regardin batch scripting

Ravioli

Microboner
Joined
Nov 1, 2004
Messages
5,097
Reaction score
2
Im boored so im trying to learn some simple scripting of batch files. So i wrote a script that scans the folder that the bat file is in, with the option of chosing "Scan" or "Quit" and if you scan, you get to choose to scan again or quit, and it loops that way.

It works perfect, but there is one problem. It works ONLY on my computer. I send it to two different friends (using XP) and the bat file just crashes when you open it. Im using Windows 7 and it works for me, but i dont see how the differences in Windows can cause problems, because the DOS is essentially the same (when it comes to simple batch files) right?

I uploaded the bat file, please try it out and tell me the results and the OS you are using. Dont worry its not a virus, open it with notepad if you dont trust me, save it as .bat to test it.
If you still dont trust me, copy this code into notepad and save as .bat and try it.

@echo off
echo This tool will scan all the files in this folder
echo Press S to Scan
echo Press Q to Quit
choice /c:SQ
if errorlevel 2 goto Q
if errorlevel 1 goto S
echo.
:START
:S
dir /s
echo. Press S to scan again
echo. Press Q to Quit
choice /c:sq
if errorlevel 2 goto Q
if errorlevel 1 goto S
echo.
:S
goto START
:Q
exit

So does anyone know what might cause this problem? Is it only my computer that works? Or is it only Windows 7 computers that works?
EDIT: sry for typo in title of thread, regardinG
 

Attachments

Seems like it works. Windows Vista Premium 64bit.

testya2.jpg
 
Thanks. I think i figured out what the problem is. The file uses a command called "choice" which vista/windows7 seems to have in cmd, but Xp does not. If you open cmd and type "choice" it gives you y/n, but if you do it in XP, it does not recognize it.

So what would be the equivilent of "choice" in XP?
 
http://commandwindows.com/batch.htm

"Prompting for user input

You can also interact with a user and ask that data be entered. The old DOS had a "Choice" command for very limited interaction but that has been superseded in Windows XP/Vista by the more versatile "set /p". The syntax is: set /p variable= [string] "Variable" is the name of the variable that will be assigned to the data that you want the user to input. "String" is the message that the user will see as a prompt. If desired, "string" can be omitted. Here is an example that asks the user to enter his or her name: set /p name= What is your name? This will create a variable %name% whose value is whatever the user enters. Note that the user must press the "Enter' key after typing the input.

(The "Choice" command has returned as a more powerful version in Vista.)"
 
I read the title as "Little help regardin batch slapping" and lol'd.

...Sorry, I have nothing to add. Just wanted to say that. :D
 
damn :( so everything i write wont work in xp? That other "set /p" method is a pain in the ass.
 
Back
Top