68

What is the best command to move all files from one folder to another?

I want to do this from within a batch file.

0

9 Answers 9

64

You can use move for this. The documentation from help move states:

Moves files and renames files and directories.

To move one or more files:
MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination

To rename a directory:
MOVE [/Y | /-Y] [drive:][path]dirname1 dirname2

  [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.

The switch /Y may be present in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.  Default is
to prompt on overwrites unless MOVE command is being executed from
within a batch script.

See the following transcript for an example where it initially shows the qq1 and qq2 directories as having three and no files respectively. Then, we do the move and we find that the three files have been moved from qq1 to qq2 as expected.

C:\Documents and Settings\Pax\My Documents>dir qq1
 Volume in drive C is Primary
 Volume Serial Number is 04F7-0E7B

 Directory of C:\Documents and Settings\Pax\My Documents\qq1

20/01/2011  11:36 AM    <DIR>          .
20/01/2011  11:36 AM    <DIR>          ..
20/01/2011  11:36 AM                13 xx1
20/01/2011  11:36 AM                13 xx2
20/01/2011  11:36 AM                13 xx3
               3 File(s)             39 bytes
               2 Dir(s)  20,092,547,072 bytes free

C:\Documents and Settings\Pax\My Documents>dir qq2
 Volume in drive C is Primary
 Volume Serial Number is 04F7-0E7B

 Directory of C:\Documents and Settings\Pax\My Documents\qq2

20/01/2011  11:36 AM    <DIR>          .
20/01/2011  11:36 AM    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  20,092,547,072 bytes free

 

C:\Documents and Settings\Pax\My Documents>move qq1\* qq2
C:\Documents and Settings\Pax\My Documents\qq1\xx1
C:\Documents and Settings\Pax\My Documents\qq1\xx2
C:\Documents and Settings\Pax\My Documents\qq1\xx3

 

C:\Documents and Settings\Pax\My Documents>dir qq1
 Volume in drive C is Primary
 Volume Serial Number is 04F7-0E7B

 Directory of C:\Documents and Settings\Pax\My Documents\qq1

20/01/2011  11:37 AM    <DIR>          .
20/01/2011  11:37 AM    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  20,092,547,072 bytes free

C:\Documents and Settings\Pax\My Documents>dir qq2
 Volume in drive C is Primary
 Volume Serial Number is 04F7-0E7B

 Directory of C:\Documents and Settings\Pax\My Documents\qq2

20/01/2011  11:37 AM    <DIR>          .
20/01/2011  11:37 AM    <DIR>          ..
20/01/2011  11:36 AM                13 xx1
20/01/2011  11:36 AM                13 xx2
20/01/2011  11:36 AM                13 xx3
               3 File(s)             39 bytes
               2 Dir(s)  20,092,547,072 bytes free
0
40
move c:\sourcefolder c:\targetfolder

will work, but you will end up with a structure like this:

c:\targetfolder\sourcefolder\[all the subfolders & files]

If you want to move just the contents of one folder to another, then this should do it:

SET src_folder=c:\srcfold
SET tar_folder=c:\tarfold

for /f %%a IN ('dir "%src_folder%" /b') do move "%src_folder%\%%a" "%tar_folder%\"

pause
2
  • 11
    To avoid the (possibly) unwanted crooket folder structure, I found that an asterix fixes this in the sourcefolder, i.e. move c:\sourcefolder\* c:\targetfolder will move the content of sourcefolder instead of moving sourcefolder.
    – Therkel
    Commented Dec 7, 2016 at 9:08
  • You have to change the delimitor when the directory contains files of directories which contains spaces: for /f "delims=|" %%a IN ('dir "%src_folder%" /b') do move %src_folder%\%%a %tar_folder%
    – ARN
    Commented Jan 16, 2019 at 9:33
28

This command will move all the files in originalfolder to destinationfolder.

MOVE c:\originalfolder\* c:\destinationfolder

(However it wont move any sub-folders to the new location.)

To lookup the instructions for the MOVE command type this in a windows command prompt:

MOVE /?
0
8

robocopy seems to be the most versatile. See it's other options in the help

robocopy /?
robocopy SRC DST /E /MOV
1
  • 5
    Note that the /MOV option means "move files, and delete them from the source after they are copied" and /E means "copy subdirectories". This effectively moves all files out of the source folder and its subfolders and recreates the folder structure under the destination folder, leaving you with an empty source folder and structure; also it will create the destination folder if doesn't already exist. Robocopy is very powerful, here's the documentation. Note especially the /MOVE option (as opposed to /MOV above).
    – Mesagoma
    Commented Aug 21, 2017 at 5:36
6

Lookup move /? on Windows and man mv on Unix systems

2
  • 3
    move --help? On Windows? Really? Have you tried that? :-) I think you mean move /? or help move.
    – paxdiablo
    Commented Jan 20, 2011 at 3:33
  • On Windows, move --help results in The system cannot find the file specified..
    – aphoria
    Commented Jan 20, 2011 at 14:08
3

You can use the command move

move <source directory> <destination directory>

Reference

2

use move then move <file or folder> <destination directory>

2

Be sure to use quotes if there are spaces in the file path:

move "C:\Users\MyName\My Old Folder\*" "C:\Users\MyName\My New Folder"

That will move the contents of C:\Users\MyName\My Old Folder\ to C:\Users\MyName\My New Folder

1
  • 1
    gives error The filename, directory name, or volume label syntax is incorrect. Commented Jul 14, 2022 at 4:58
1

Command will move All Files and Sub Folders into another location in 1 second.

move "your source path" "your destination path" 

Hint : To move all Files and Sub folders

move "f:\wamp\www" "f:\wapm_3.2\www\old Projects"

enter image description here

you can see that it's before i try some other code that was not working due to more than 1 file and folder was there. when i try to execute code that is underlined by red, then all folders move.

Total 6.7GB data moved in 1 second... enter image description here

1
  • All folders has Laravel Projects .so you can assume that how much file moved in just 1 second.
    – pankaj
    Commented Aug 13, 2020 at 17:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.