Windows XP Batch files

Rumpel Tumskin

Junior Member
Sep 20, 2007
12
0
0
I have to do a batch file for a class but I just don't know enough about the Command Prompt to get it right. It is fairly simple

1. Write a batch file that creates a directory named asg5.
2. Then change the cursor to the new directory (asg5).
3. Display the system time without changing it and save the data as time.txt.
4. Now lists the contents of the new directory (asg5).
5. Set a pause before closing.

So far I have...

md asg5
time > time.txt
dir
pause

this creates the asg5 folder on the desktop and the time.txt file also on the desktop. I can't figure out how to change the asg5 folder tot he active directory and have time.txt created there, then have the cmd prompt show a dir command for that folder.

Help please.
 
Aug 4, 2007
38
1
61
I was going to answer this question for you, but then I remembered that the purpose of a lesson is the journey, not the destination.

The reason this batch file is not working the way you intend it to, is becuase you are missing part of the fundimental basics of how batch files (and linux shell scripts) operate. Please review your source material or visit the following site for instructions. Your answers will be there.

http://www.robvanderwoude.com/batchstart.html

Scripting is great fun!
 

Rumpel Tumskin

Junior Member
Sep 20, 2007
12
0
0
LOL, this is for a A+ certification class at a college i am going to. Our teacher gave us thses batch file assignments and the book doesn't talk about them and he has never gone over how to do them either. I guess he just expects us to know DOS.
Thanks for giving me a direction to go in.
 

Rumpel Tumskin

Junior Member
Sep 20, 2007
12
0
0
Here is what the teacher sent me back to show what it should be

md .\asg5
time /t > .\asg5\time.txt
cd .\asg5
dir
pause

Where can I find info on what all the .\ , /t, and > symbols do and a big list of them. Every help tutorial I find on batch files really do not discuss these characters, they just talk about the commands. I can't figure out how to do freaking batch files untill I can find a good guide to teach me how to use the command prompt. I need a "Dummies" quality web guide.
 
Aug 4, 2007
38
1
61
Originally posted by: Rumpel Tumskin
Here is what the teacher sent me back to show what it should be

md .\asg5
time /t > .\asg5\time.txt
cd .\asg5
dir
pause

Where can I find info on what all the .\ , /t, and > symbols do and a big list of them. Every help tutorial I find on batch files really do not discuss these characters, they just talk about the commands. I can't figure out how to do freaking batch files untill I can find a good guide to teach me how to use the command prompt. I need a "Dummies" quality web guide.

Ok, I really can't believe that aren't teaching you these things. I learned this stuff in seventh grade! (That's Canadian public schools for ya).

The \ is the same thing as the \ in C:\Windows\System32 - it's part of the "path" to a file. In Windows, the path starts at the disk drive letter, such as C:\ or A:\ and everything is stored on the computer in directories (folders) underneath the drive letter. Take your My Documents folder, it's located in Windows XP at C:\Documents and Settings\Rumpel Tumskin\My Documents, where each "level" of directories is divided by a \ or "backslash".

So, if you are in a location on the computer, such as C:\hp\temp\ and you want to access a file in C:\hp\tools you'd type the following on the command line:

cd ..\tools

Where cd means "change directory", the first . means "current directory" and the second . means "the directory before the current directory and the \tools means "the directory called tools. So, cd ..\tools means "jump back one directory lower, then jump up into the tools directory from there".

You teacher is only using one period, so what he is doing is simply "specifying the path" to be the current directory - it was "specifying the path" that you were missing, when I mentioned that you were missing a crucial concept. They taught us way back when that computers are picky and they will only do exactly what we tell them to do. And, back then it was important, because not specifying the path can cause lost data, lost time, and lost hair!

The reason I mentioned the .. is that is very handy when working on the command line. In linux and in dos, you use it all the time when using the cd (change directory) command, such as

cd ..

to jump back one directory

cd \

to jump all the way back to root of the drive, C:\

and

cd ..\..\tools\uninstall.bat

to run a file "2 jumps down, 1 jump up" from your current location!

I''s all very handy stuff that I take for granted, as ''ve know how to do it for something like 20 years now... I AM old... Anyhow, to explain the other characters,

/t is wha''s called a "switch" or "parameter" in Windows. Many command line programs, such as time and dir have multiple switches that allow the program to output (or input) different information. Pretty much all dos progams will output some helpful information if if they are followed by the /h switch (time is not one of them...). time /t tells the time command to output the time in the 12:00 AM format, rather than military time.

> and >> are "redirectors" that simply do exactly what that sounds like: they redirect the output of one program into the input of another file or program. So,

time /t > .\asg5\time.txt

means, "take the time output from time /t and put in a text file called time.txt, which is located one directory up from the current location and is called asg5".

An important thing to note is that a > redirection into a file will overwrite the contents of the file starting at the first byte, where as the >> redirection means, "stick this crap after the last character in the file", otherwise refered to "appending". Both are very handy operators in any scripting language!

Well, I hope that helps some. If not, you could head to www.linux.org and download one of the very small floppy disk versions of linux and play around with the bash scripting howtos. bash stands for "bourne again shell", after the guy (Bourne) who wrote a new *nix shell. sh is the standard unix shell, where bash is the standard linux shell. Anyhow, linux shell scripting is more powerful and rewarding than dos shell scripting (and more relivent today), but the underlying concepts of both dos and linux shell scripting are the same - they both are derived from the unix of the 1960s!

Good luck with your classes and best wishe