These pages are all about the Windows operating system and the command-line interface. For information about how to write batch scripts and it's programming syntax, see the Batch page.
Did you know that MS-DOS has an auto-complete function, just like Linux, except it's turned OFF by default? To turn it on, type the following into the command line:
And to turn it off again (why would you ever want to do such a thing!):
Now, to use it! It works slightly different to Linux. Instead of one button (tab), there are two. Press Ctrl-D to auto-complete directories, or Ctrl-F to auto-complete files.
If there are multiple choices, pressing the button repeatedly will cycle through the options.
There are two ways to display comments:
rem This is a comment : This is also a comment, and using a much simper keyword than rem
To display a list of files and folders in the current directory, use the command:
This will display the full-length filenames/foldernames. To display the names in short format (6 letters, a matilda (~) and then a numeral, usually 1, followed by the extension), use the following:
xcopy is a native Windows command which copies files and folders. It has more features than the copy command.
xcopy source [destination] [/a] [/b] [/c] [/d [:date]] [/e] [/f] [/g] [/h] [/i] [/j] [/k] [/l] [/m] [/n] [/o] [/p] [/q] [/r] [/s] [/t] [/u] [/v] [/w] [/x] [/y] [/-y] [/z] [/exclude:file1[+file2][+file3]...] [/?]
xcopy does not have any support for resuming an interrupted command. So if you are in the middle of copying a large number of files, and it gets interrupted (the connection drops, a fileame is too long, e.t.c), you will have to start again.
In Windows 95 and 98, two versions of
xcopy are natively available,
xcopy32. When using
xcopy32 is automatically called if inside a Windows environment. For this reason, you never have to call xcopy32 directly.
There are more advanced command-line Windows copy programs, such as
robocopy, which supports resuming. If you are looking for a GUI, try RichCopy. Although I have had RichCopy v4.0 crash on me when coming across multiple files which have file names too long for Windows to support.
xcopy wasn't enough, there is also
robocopy first shipped with the XP Resource Kit, and was provided standard with Windows 7 and 8.
The standard syntax is:
robocopy source_folder destination_folder [files_to_copy] [options]
where files_to_copy defaults to
*.* (all files) if nothing is provided.
The most popular options are (in rough order of popularity):
|\s||Copy all sub-folders also (similar to recursive mode in Linux systems)|
|\MOV||Move files rather than copy them (i.e. delete after copy). This does not delete directories, use \MOVE for that.|
|\MOVE||Moves files and folders rather than copy them (i.e. delete after copy). If you only want to move files, and not delete directories, see \MOV.|
|\r:n||Retry failed copies n times. Default is 1 million! This can be a bit ridiculous, especially with a 30s wait period between retries. For backing up large amounts of data, I recommend setting this to a lower value (e.g. \r:1), and then investigating how many fails occurred after the transfer is complete.|
Deleting Files And Directories
Confusingly, windows has a range of different delete commands, and the one you need use depends on what version of windows you are running, and whether you are deleting files, empty folders, or folders containing files.
# Delete a file (1st way) del filename.ext ## Delete a file (2nd way) # Note that "del" and "erase" are the same command erase filename.ext ## Remove a directory which is empty rmdir directory-name # Remove a directory which is not empty rmdir directory-name /S