-1

Every month I have a very large number of files (in many subfolders) in a particular folder. I need to move them all into a different folder. In an attempt to automate the process of moving them I used robocopy in a batch file. It works fine, but takes HOURS to run. (It is many many GB).

Now, if I do it manually in Windows Explorer, by opening said folder, selecting all, and right-dragging to destination folder, and choosing "Move Here", it moves INSTANTLY. (Windows XP must be pruning and grafting the directory entries, without ever making a second copy of the files. ... and yes, source and destination are on same partition.)

So, QUESTION IS: Does anyone know of a program I can run from a batch file to move files in this instantaneous way? (need to move entire sub-folder tree)

Harry Johnston
  • 35,639
  • 6
  • 68
  • 158

2 Answers2

1

You can use MOVE for this:

C:\>MOVE /?
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.

For example:

C:\Users\test>mkdir to
C:\Users\test>move from\*.txt to
C:\Users\test\from\1.txt
C:\Users\test\from\2.txt
        2 file(s) moved.
psmears
  • 26,070
  • 4
  • 40
  • 48
  • Tried out MOVE on a 200 GB file, and you're right, it is instant (within the same partition)! I wouldn't have believed it if I didn't try it. But now I need to find some weird complicated FOR loop to recurse the subdirectory structure?? –  Apr 01 '15 at 19:43
  • Tried to vote your answer up, but don't have the rep. –  Apr 01 '15 at 19:43
  • @Tom: You don't have to recurse - you can use `MOVE` on a directory, and it will move the directory and its entire contents all in one go. – psmears Apr 01 '15 at 20:15
  • It does not recurse directories for you and it cannot move an entire directory tree (with subfolders and files) to a destination inside an entirely different folder on the partition. I tried: `move "L:\Backups\Source" L:\DEST` it said "access denied" I tried `move "L:\Backups\Source\*.*" L:\DEST` and it only moved the files inside Source, but not the subfolders or their files. –  Apr 01 '15 at 21:35
  • @Tom: It *can* move an entire directory tree in one go, I promise! There may be another issue preventing it in your case, but I've tried it many times and it does work. Are you sure the user you're running as has permission to move (and hence delete) the `Source` folder itself, not just its contents? – psmears Apr 01 '15 at 21:49
0

With a point in the right direction from @psmears, and a lot of googling, I found the (or a) solution:

@echo off

setlocal ENABLEDELAYEDEXPANSION


REM  ** Change to source dir

L:
cd "L:\Backups\Source"



REM  ** Move files recursively

for /R %%G in (.) do (

set mydir=%%G
set mynewdir=!mydir:~18!

md "L:\DEST\!mynewdir!"
cd "L:\DEST\!mynewdir!"
move "%%G\*.*" .

)



REM  ** Remove now-empty sub-dir structure inside source

L:
cd "L:\Backups\Source"

for /f "usebackq delims=" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d"