help with dos commands for class... creating batch file

fohawk17

New Member
i have to create a batch file for a class of mine. the requirements are that its makes a folder on a drive, makes a subfolder in that same folder. lists the volume label, asks if the user would like to change the volume label, copys chkdsk over to the drive, copies sort over to the drive, runs both, then gives a finished message. i have everything else, but i do not know how to do the label change choice. anyone know how to do it? the percent one is just so i can specify which drive to do all of this to

here are the contents of my batch file

cls
mkdir %1\CITF120
mkdir %1\CITF120\STRAYER
VOL %1
PAUSE
copy C:\WINDOWS\SYSTEM32\CHKDSK.EXE %1\CITF120
PAUSE
COPY C:\WINDOWS\SYSTEM32\SORT.EXE %1\CITF120
PAUSE
DIR %1\CITF120
PAUSE
%1\CITF120\CHKDSK.EXE %1 /F
PAUSE
%1\CITF120\SORT.EXE %1\DOSHMWRK.TXT
PAUSE
ECHO OFF
ECHO YOUR PROCESS IS FINISHED, GOOD JOB!
PAUSE
 
Last edited:
set /p labelchange=Do you want to change the label (Y/N)?

if /i %labelchange% equ y (
set /p label=Give me a name:

echo You gave me: %label%
echo.
echo Syntax for label:
label /?​
)
 
so i would just add it to the end after the last pause, or remove the last pause and then put it there? and the parenthesis are supposed to be spaced out funny like that?
 
so i would just add it to the end after the last pause, or remove the last pause and then put it there? and the parenthesis are supposed to be spaced out funny like that?

You could do it right after the mkdir commands or at the end, it doesn't matter. I haven't written batch files in many years though since all I do now is manage Unix systems.
 
You don't really need to indent the block, but it is good pratice (in any programming language). It clearly shows what block that will be executed if the if-sentence is true.

You can get the syntax of every command by appending /? ...

set /?
if /?

etc
 
and the parenthesis are supposed to be spaced out funny like that?

Opps didn't address this. When looking at tons and tons of code you can indent to make each part of the code look easier, for example

Code:
function woman {
  tmpfile="/tmp/man ${*}.pdf"
        if [ \! -f "${tmpfile}" ]
              then man -t "${*}" | pstopdf -i -o "${tmpfile}"
        fi
  open "${tmpfile}"
}

and this

Code:
function woman {
 tmpfile="/tmp/man ${*}.pdf"
 if [ \! -f "${tmpfile}" ]
 then man -t "${*}" | pstopdf -i -o "${tmpfile}"
 fi
open "${tmpfile}"
}

and technically this

Code:
function woman { tmpfile="/tmp/man ${*}.pdf" ; if [ \! -f "${tmpfile}" ] then man -t "${*}" | pstopdf -i -o "${tmpfile}" fi ; open "${tmpfile}" }

Are basically the same thing. I am not sure if the last example would work as a function, but you can (in shell) string commands one after another with a semi colon (;) on the command line and execute multiple commands at once. Obviously, the first example is way cleaner to read. It also depends on how you declare white space, but that is going off topic.
 
Last edited:
one more thing. if i were to just use the label command, would there be a way to set a countdown? say if they dont put in a new name after 5 seconds it stays the same?
 
yes i have powershell, is that basically like edit.com?

Oh no my good man, the powershell is a lot like a unix shell but for windows. It is a whole new language that has only been available via extra download until windows 7. I think it will totally replace batch, but it is still sorta new so to speak. In your case it may not bee sleep, that may only be a Unix command.
 
Back
Top