Batch Script Moving Folders
Moving Folders
Batch Script provides the move
command for moving folders.
move [/y | /-y] [drive:][path]filename1[,...] destination
Following are the description of the options which can be presented to the move
command.
Options | Description |
---|---|
[drive:][path]filename1 | Specifies the location and name of the file or files you want to move |
destination | Specifies the new location of the file. Destination can consist of a drive letter and colon, a directory name, or a combination. If you are moving only one file, you can also include a filename if you want to rename the file when you move it. |
[drive:][path]dirname1 | Specifies the directory you want to rename. |
dirname2 | Specifies the new name of the directory. |
/y | Suppresses prompting to confirm you want to overwrite an existing destination file. |
/-y | Causes prompting to confirm you want to overwrite an existing destination file. |
You can only move directories within the same drive!
Otherwise, you will get an accessed denied
error.
The move
command does not touch the file itself: it only changes the file allocation table.
This is why a file cannot be moved to another drive, and any move to another drive must be done using a copy.
Examples
Let’s look at some examples of moving folders.
The following command will move all files from the current directory to the folder C:\Example.
move *.* C:\Example
The following command will move all files with the .txt extension from the current directory to the folder C:\Example.
move *.txt C:\Example
The following command will move all files from the folder called old in C drive to the folder C:\Example.
move C:\old\*.* C:\Example