Move to a Different Directory
Here, we will show you how to move a specific file to another directory using batch files or Command Prompt with concrete examples.
Commands to Use
To move a file name, use the move
command. As the name suggests, it is used to move files or folders from A to B.
Executing from Command Prompt
Here is an example of moving a file named “disposable.txt” saved in the current directory to My Documents.
Executing from a Batch File
@echo off
setlocal
set FOLDER=%userprofile%\Documents\
set FILE_NAME=disposable.txt
move %FILE_NAME% %FOLDER%
endlocal
exit
For more detailed usage of the move
command, please refer to the following page:
Creating Folder Structures
The move
command allows the use of wildcards in the first argument. This can be used to move specific file names or files with specific extensions in bulk.
Executing from Command Prompt
Assume that you have a rule to add “done_” to the beginning of file names for completed work files.
Here is an example code to move completed work files to the “Completed” folder in My Documents.
Executing from a Batch File
@echo off
setlocal
set FOLDER=%userprofile%\documents\Completed\
set NAME=done_*
move %NAME% %FOLDER%
endlocal
exit
There may be situations where you want to move files and rename them in bulk.
In that case, you can use the rename
command.