Part 1. Starting off.
Welcome to Tutland.
As this is my first tutorial on this kinda new blog, im gonna introduce you to how this works.
Every Article cointains a part of a tutorial. You can simply find through this as the name of the tutorial is the title and the part is the subtitle.
That means that when you are finished reading this part and want to go on, go find Batch programming for beginners Part 2. Which i dont have a name for yet.
Well lets begin.
First of this tutorial is for newcomers so if you got just a little idea about what batching is then you might not get anything out of reading it.
The tutorial will explain the following.
The basic commands
Your first code
Here we go.
If you are familiar with MS-DOS you might have an idea to how it works.
Batch is a file which inject commands into MS-DOS or Command Prompt depending on if you are using any OS with GUI or not.
The idea with bath is to make some work without typing in every command up to more times.
There are different ways of making a batch file.
You can go Start Menu >> Run.. and then type "cmd" in the field. if using Windows NT4 or lower you might have to use "command" instead of "cmd"
When the Command Prompt comes up type in "cd desktop" and press enter.
Then type "edit batch.bat" and press enter.
Then your editor will come up.
Else you can just use notepad.
The basic commands.
Now that you actually might have an idea on what it is we can go on.
With batch you will be able to run programs, copy files, delete files, edit text files, move files, and millions of other things
Now heres the commands.
Write something to the screen. Im not sure if you can use Print too but you can in PHP, i really prefer using echo as that command also appears in the beginning of the code in most scripts.
You do not need quotes of any type.
Syntax: echo What to say
Delete a file.
You can use * as a wildcard so DEL "*.*" will delete any file in the choosen directory which by default is C:\Documents and Settings\username\ (username is your name on the computer)
Syntax: DEL "[relative or full path]"
Use this to choose which directory you want to work from or make a relative path from.
Syntax: CD "[relative or full path]"
Copy one or more file(s) and/or folder(s) (Gosh, What a surprise .)
Syntax: Copy "[file to copy]", "[another thing to copy]" "[destination folder]"
Move one or more files and/or folders
Syntax: Same way as copy command
Your first script
It might be hard to understand but i will explain it underways if possible.
Make a comment if theres something you want explained or or anything likely.
Now open notepad.
Goto Start >> Run, type notepad and press enter.
To start making your code you must decide what its for.
For some reason you might want to turn input showing off.
If you want to copy something and you make the code with a Copy entry and then run it you will see the command shown when executed.
This is "Echo" and with echo set on it will also show up viewing your code.
If set to off you will only see the output of the commands.
If you set >nul at the end of a command you wont see anything.
Echo is turned on as default and you might often want to turn it off.
In the beginning of your code type @echo off
That is supposed to be the only you write and you can switch it on and off as often as you want, but its just confusing if its showing up with your input anyways.
Now you might want it to actually do something.
Use the Copy command to copy anything small and write that down right after the command to turn off echo like this:
- @echo off
- Copy "not important.txt"
This will copy the file named not important.txt .
As we got no destination folder it will just copy it to where it is now
Copy "not important.txt" "\dir"
It should be moving the file into the folder named dir
Because i didnt start with a drive letter like C:\ it will move it to a relative directory.
A relative directory is used in order to get a shorter path.
You will use them as shortcuts and they work like this:
If you have the file at the desktop and want it to the directory
C:\Documents and Settings\Username\Desktop\123
you will also just be able to type \123 instead of the long path above.
If you are in the directory 123 as shown before and want back to desktop you can still use a relative path.
I were some time about to figure it out but if you type \..\ it will go 1 directory back
Command to move from 123 to Desktop is:
And Vice versa:
Still not finished