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
Etihtsarom

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
riteshtechie

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
Strahan

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
Etihtsarom

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
WindowsStar

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
Strahan

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
Strahan

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
kalas72

Windows7 Ultimate 64 bit
 
 

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

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
Strahan

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




Similar help and support threads
Thread Forum
Batch file not waiting for command to finish before moving on
Hiya, i wasn't really sure where to put this, and i have Googled it but i can't find a reason why my batch file no longer does what it used to do. According to everything i've read, my batch should stop at IE, until i close IE, whereupon it should continue. This is how it used to behave. Here it...
Software
search multiple files, copy+paste to new folder (batch file software?)
I am a complete newbie when it comes to batch files and batch file software, so apologies in advance. I've done some research on Google etc but I seem to just be getting more and more confused trying to use various different scripts and programs and reading different info on various websites. ...
General Discussion
Custom batch file that copies font files to another folder?
I just downloaded all of the Google Web Fonts and they were each downloaded into their respected folders, so instead of clicking on folder after folder and right clicking after right clicking and finally installing each and every font; How can I create a command prompt (batch) file so the prompt...
General Discussion
Need advice on batch file for moving files using Send To
Okay, here's what I want to do. I want to be able to have an entry in my "Send To" submenu to move (not copy) whatever files I have selected to "C:\Hold" With my very limited knowledge of batch files, I made a simple .cmd file that I put in the Send To folder with the following line: move %1...
General Discussion
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion
moving files and defragmentation state of file/folder
When you move or copy files from one folder and/or drive to another...if the original file(s) is fragmentated...will the file be moved as is or will the file be placed in the new location in a relatively none fragmented state ? Or...do you have to defragment the drive/file first before moving...
Performance & Maintenance


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 23:49.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App