Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Batch file for moving files to folder?


04 Jan 2010   #1

7 Prof
 
 
Batch file for moving files to folder?

Hello,
Wanted to see if any one here wouldn't mind writing a batch file or script that would move multiple files to a target folder. Here are the specifics:
HDD1 Contains Folders A,B,C,etc...
Folder A contains Folder A1 which contains File A2
Folder B contains Folder B1 which contains File B2
Folder C contains Folder C1 which contains File C2
Folder D contains Folder D1 which contains File D2
Folder E contains Folder E1 which contains File E2
Folder F contains Folder F1 which contains File F2

And what I need to do is move A2,B2,...F2.. to the drive root.

This would really save some time over moving these files manually, because they're numerous.
Or if you know of any utilities that can do this, please let me know
Thanks.


My System SpecsSystem Spec
.

04 Jan 2010   #2

Windows 7
 
 

I am assuming that these all folders are in X drive

such that your file A2.xxx is in X:\Folder A\Folder A1

Quote:
move "X:\Folder A\Folder A1\File A2.xxx" X:\
move "X:\Folder B\Folder B1\File B2.xxx" X:\
move "X:\Folder C\Folder C1\File C2.xxx" X:\
move "X:\Folder D\Folder D1\File D2.xxx" X:\
move "X:\Folder E\Folder E1\File E2.xxx" X:\
move "X:\Folder F\Folder F1\File F2.xxx" X:\
save it as bat file.
If you are using windows 7 than open the file in Administrator mode.

I hope it will help
My System SpecsSystem Spec
04 Jan 2010   #3

Win 7 RC, Win XP, Win 2003, Ubuntu
 
 

Another alternative to do it:

for %s in (A B C D E F) do move "x:\Folder %s\Folder %s1\File %s2.xxx" x:\

That's assuming you type it at the command line. If you put it in a .BAT file, make every % in the line above %%.
My System SpecsSystem Spec
.


05 Jan 2010   #4

7 Prof
 
 

Thanks for the suggestions. The problem here is that A B C D ... are really long folder names and there are tons of those folders. It simply isn't practical to have to list the actual folder names. I'm looking for something that just dumps all the elements of all folders out to root.
My System SpecsSystem Spec
05 Jan 2010   #5

Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
 
 

First off it is never and I mean never good to copy files to the root of any drive. Especially C: (if that is your OS drive). It would be much better to move them to X:\MovedFiles or something like that.

Is there some sort of pattern to the folders off the root? Or are you moving everything from all folders off the root? If this is on your C: Drive the script would move everything from the C: drive including Windows (that is if the OS did not protect itself) but it would do a lot of damage. If all the folders are on another drive that would be best, but again if there is no pattern it will be hard to move files without moving files you don't mean to.

Let me know.
My System SpecsSystem Spec
05 Jan 2010   #6

Win 7 RC, Win XP, Win 2003, Ubuntu
 
 

If there isn't a pattern, how about non-move folders? There can't be all that many of those. You could do a dir c:\ /ad/b >folderlist.txt at the command line then open folderlist.txt in notepad and search for the folders you don't want moved and remove those lines. Save the file then you can do a for /f and use the .txt as the input source for the folder list to move.
My System SpecsSystem Spec
05 Jan 2010   #7

Win 7 RC, Win XP, Win 2003, Ubuntu
 
 

PS, what is the file extension of the files you want dumped in root? If it's something odd that will only exist in those special folders an easy solution would be:

for /f "tokens=*" %s in ('dir x:\*.weirdextn /s/b') do move "%s" x:\

I also agree with WindowsStar though.. it's usually not prudent to just dump all that stuff to root.
My System SpecsSystem Spec
05 Jan 2010   #8

Windows7 Ultimate 64 bit
 
 

I used n2ncopy in the past and it works very good.
My System SpecsSystem Spec
05 Jan 2010   #9

7 Prof
 
 

Quote   Quote: Originally Posted by Strahan View Post
PS, what is the file extension of the files you want dumped in root? If it's something odd that will only exist in those special folders an easy solution would be:

for /f "tokens=*" %s in ('dir x:\*.weirdextn /s/b') do move "%s" x:\

I also agree with WindowsStar though.. it's usually not prudent to just dump all that stuff to root.
This might work. I'll give it a try later on. There are altogether about 15 types of files accross all folders, so a much simpler solution would be a search for file types in the drive (not C drive btw) and just move them, albeit 15 times.
My System SpecsSystem Spec
06 Jan 2010   #10

Win 7 RC, Win XP, Win 2003, Ubuntu
 
 

Cool. Another alternative to automate it to cover your varied filetypes:

for %s in (ext1 ext2 ext3 ext4) do for /f %t in ('dir x:\*.%s /s/b') do move "%t" x:\

That way you only have to type in the exts once and it does the relocations automatically.
My System SpecsSystem Spec
Reply

 Batch file for moving files to folder?




Thread Tools




Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 09:32 PM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33