• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1659
  • Last Modified:

Move files within directory tree

I have a directory c:\test that has files and subfolders inside it. I would like to move all of the files within that folder to g:\. I do not want to copy the directory structure, just the files.  I will be deleting the whole c:\test folder and it's subfolders afterwards. I'd prefer to use robocopy as it seems to run a bit faster than xcopy, and I have a large amount of files to move, but if that's not possible I can use whatever works.
0
ptuttle1319
Asked:
ptuttle1319
  • 5
  • 4
  • 4
1 Solution
 
Steve KnightIT ConsultancyCommented:
Try:

for /r "C:\test" %F in (*.*) do move "%~F" "G:\%~nxF"

Run down all subdirs of C:\test and for each give the move command the filename and path then just the filename and extension in G:\

Steve
0
 
Steve KnightIT ConsultancyCommented:
Use %% instead of % if putting in a batch file - that is for cmd.exe prompt.
Steve
0
 
ptuttle1319Author Commented:
There are thousands of subdirectories under the root. Is there a way to crawl the sub-directories without having to go run the script in each folder?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Steve KnightIT ConsultancyCommented:
It already does, or should do.  The /r says to recurse down all subdirs.  It should run a move command for all files down the whole structure and move them all into the top level g:\ without any subdirs.

You could also go in explorer to the top level, search for all files, select them all and cut / paste them to G:

Steve
0
 
Bill PrewCommented:
You might try xxcopy as a way to get better performance, it has support for flattening a directory structure into a single folder during a copy via the /SX switch.  Free for personal use, but a great copy tool and worth the money for the professional use version.

http://www.xxcopy.com/

~bp
0
 
Bill PrewCommented:
Steve's approach will work, but it processes one file at a time.  You might want to try this approach if you want to stick with basic commands, as it does each group of files in a folder with a single move command.  Just type this in at a DOS command prompt and it should move all the files.

for /D /R "C:\Temp" %A in (*.*) do move "%~A\*.*" "I:\"

Open in new window

~bp
0
 
ptuttle1319Author Commented:
Is there a way to put in a switch for an implicit Yes or All to file overwrites? There will be quite a few that will need to be overwritten.
0
 
Bill PrewCommented:
Sure, add the /Y switch to the move command.

~bp
0
 
Steve KnightIT ConsultancyCommented:
Good idea Bill, move shouldn't be much of an issue unless it is loads of tiny files vs lots of bigger ones where the batch file processing per line out ways the time to move to a different partition.

It may well also be better to "move" them to the same partition/drive which is a relatively 0 time operation and then later copy them elsewhere -- in that way you wouldn;'t have to copy files twice etc.

Steve
0
 
ptuttle1319Author Commented:
for /r "C:\test" %F in (*.*) do move /y "%~F" "G:\%~nxF"
0
 
ptuttle1319Author Commented:
I was able to get Steve's script to work without any issue, thanks!!
0
 
Steve KnightIT ConsultancyCommented:
Thanks, glad it helped....

Bill - is it me or have the MSDOS / scripts area gone very busy tonight?
0
 
Bill PrewCommented:
Yes, over the last week or so there seems to be more MSDOS activity. And me without a lot of time to spend on EE right now...

~bp
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now