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: Help batch file to move files in list to created subdirectory

18 Nov 2015   #1
beazleybub

w10
 
 
Help batch file to move files in list to created subdirectory

Please excuse me in advance because I am not very experienced making batch files. I'm not asking for a free lunch and would gladly paypal someone some cash for a working batch file.

I have a parent folder that contains several subfolders. Each subfolder has several files in them. I need a batch file to search all the folders starting from the parent folder for files contained in a list.txt file and if it finds a match create a new folder where each file was found and move the found file to that folder.

File names in list.txt: (no extension)

test1
test2

Before batch run:

Parent
|--Sub
| |--test1.zip
| |--foo.zip
| |--foo1.zip
| |--foo2.zip
|
|--Sub2
| |--test2.zip
| |--foo.zip
| |--foo1.zip
| |--foo2.zip

After batch run:

Parent
|--Sub1
| |--NewSub
| | |--test1.zip
| |
| |--foo0.zip
| |--foo1.zip
| |--foo2.zip
|
|--Sub2
| |--NewSub
| | |--test2.zip
| |
| |--foo0.zip
| |--foo1.zip
| |--foo2.zip

I have made every effort to do this on my own and keep failing.

Thanks in advance.


I've managed to get this to work but would like to make it create subfolders where the files are found. I would also like to use move instead of xcopy if possible.

Code:
for /f "delims=" %%i in (list.txt) do xcopy "C:\Users\BEAZLEYBUB\Desktop\New folder\New folder\%%i?" "C:\Users\BEAZLEYBUB\Desktop\New folder\Copied" /i /z /y /s
pause



My System SpecsSystem Spec
.
19 Nov 2015   #2
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

​Hi Beazleybub, and welcome to SevenForums,

Well I have just the batch file for you. Recently, another member asked for something similar: a batch script that would find a bunch of files given their filenames, in the form of a new-line separated text file list, and do something with those files.

The script can be found here, post #2, and I'll give you a hint regarding what sort of options you should use:
Code:
set "output_folder=.\NewSub"
set "default_mode=MOVE"
set "include_folders=FALSE"
set "silence_errors=FALSE"
set "adapt_current_directory=TRUE"
The rest should be self explanatory. One thing to note though, each filename entry in your text file list must have an extension, unlike in your example 'list.txt'.

Good luck, Beazleybub.
My System SpecsSystem Spec
19 Nov 2015   #3
beazleybub

w10
 
 

Hey, that's pretty nifty!!! I really think the adjustable options make the script very flexible! I really appreciate your help!

I have one small issue though. Some of my filenames have spaces in them. Could you modify the script to allow this?

Cheers, Beazleybub
My System SpecsSystem Spec
.

20 Nov 2015   #4
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Quote   Quote: Originally Posted by beazleybub View Post
I have one small issue though. Some of my filenames have spaces in them. Could you modify the script to allow this?
The script already fully supports parsing filenames and manipulating files that have spaces in their name. Did you happen to find an issue relating to this? If so, please provide details.
My System SpecsSystem Spec
20 Nov 2015   #5
beazleybub

w10
 
 

In my file list I have a filename called "foo bar.txt" and the first time I tried to run it the screen just blinked. I added a pause to your script to see what was going on. The message displayed was...

Item 'foo' could not be located

0 items were copied to directory '.\NewSub'
Press any key to continue . . .

It was missing the "bar"


Thanks
My System SpecsSystem Spec
20 Nov 2015   #6
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

​I was able to replicate and fix the issue you found, which was only a display issue with that particular error message. The script would still be unable to locate your file "foo bar.txt".

Make certain the filenames listed in your text file list have extensions, for instance, specify "foo bar.txt" and not just "foo bar", or you may use wildcards, e.g. "foo bar.*".
My System SpecsSystem Spec
20 Nov 2015   #7
beazleybub

w10
 
 

I'm sorry your response is a little confusing. You said you fixed the issue but, then say there can be no spaces in the filenames. I see no reason your script couldn't be edited to parse the list file with filenames that contain spaces. Anyhow, I still appreciate your input and script, they both were very useful.
My System SpecsSystem Spec
21 Nov 2015   #8
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Quote   Quote: Originally Posted by beazleybub View Post
You said [...] there can be no spaces in the filenames. I see no reason your script couldn't be edited to parse the list file with filenames that contain spaces.
Nowhere in any post did I ever say or even come close to implying that my script doesn't support filenames containing space characters. I do recall, however, saying the exact opposite. In my post #4, I mention that filenames with spaces are fully supported by the script. Zero strings attached there, I assure you.

To be crystal clear, in my previous post I had merely pointed out that there was a minor display error with one of the error messages, to which I've now fixed. This correction did not effect the algorithm of the script whatsoever.

In your example where the script failed to find the file "foo bar.txt", the script genuinely could not locate a file named "foo bar.txt" on your filesystem, despite what the error message said about not being able to find "foo". The function that outputs the error message got passed the full name "foo bar.txt", but the function was instructed to only print the first argument (arguments delimited by space character). This is the 'issue' I have fixed.
My System SpecsSystem Spec
21 Nov 2015   #9
beazleybub

w10
 
 

That is exactly what you said!

From post #4...
Quote:
The script already fully supports parsing filenames and manipulating files that have spaces in their name.
From post #6...
Quote:
Make certain the filenames listed in your text file list have extensions, for instance, specify "foo bar.txt" and not just "foo bar", or you may use wildcards, e.g. "foo bar.*".
Do you not think the filename "foo bar" has a space in it?
Stop ranting like a contestant from Project Runway and breathe.

(wipes hands)
My System SpecsSystem Spec
22 Nov 2015   #10
Pyprohly

Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
 
 

Quote   Quote: Originally Posted by beazleybub View Post
That is exactly what you said!
What is? Please be coherent.

Quote   Quote: Originally Posted by beazleybub View Post
Do you not think the filename "foo bar" has a space in it?
You've got to be kidding, right? This shouldn't need to be questioned. There is a single, empty, well defined space between "foo" and "bar.txt", and as obvious as this appears, I can, if you wish, manage the effort to ask others to confirm this for you if you are truly unsure.

Filenames and files with names containing spaces work just as flawlessly now with the script as files lacking space characters. What is with your disagreement in post #7?


Quote   Quote: Originally Posted by beazleybub View Post
Stop ranting like a contestant from Project Runway and breathe.
I take all my works and projects seriously. I would not allow for anyone to experience an error caused by my mistake without a subsequent, apt explanation. If you are unsatisfied with practical solutions or other aid given to you, you should spend time gathering details and propose at least a constructive, meaningful response instead of insulting the person giving you assistance and wasting time engineering hypothetical similes to help your intentionally provoking endeavour. It wasn't 'rant' it was making a point clear, which clearly failed.

Quote   Quote: Originally Posted by beazleybub View Post
(wipes hands)
Uber act of rudeness. I hope you enjoy your 100% free help.
My System SpecsSystem Spec
Reply

 Help batch file to move files in list to created subdirectory




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Batch File to Move a list of files.
Hey All, I just joined this forum to find some help on a specific topic that I've been researching for like two hours now on google. I have a list of 1300 files that I need to move from one location to another (move not copy). I've found this batch file created by Neutron16 which performs a Move...
General Discussion
Move files from original folder to existing folders - w batch file?
My files have a format of "ID_date_time.d7d Ex: 11111-5_2013_10_07_142149.d7d The ID is 1111-5 and was tested 10/7/2013 at 2:21:49 PM and the file extension is always .d7d The local files are automatically saved here by the program generating the data: C:\Local\Data I want them copied...
General Discussion
Batch file to Sort and Move specific files by identifying word inside
Hi All... I will explain what I need in as much detail as possible. I need a batch file to move specific files into a separate folder,possibly by opening my hex editor,searching for the word "body" ( without the quotes ) and if found ,close hex editor,move file to a folder called "moved" ,then go...
General Discussion
[Help] Batch File move every 15.000 files to another folders
Hi guys I'm new here, please help I have about 2 million email files that i want to convert into mbox files. but the tool i used only can convert every 15.000 files. so i need a batch file that can move this 2 million files into another folder (15.000 files each folder) and the folder name...
General Discussion
Batch File - List files modified within last 7 days
Hi All, I'm trying to create a batch file that will create a text file listing all the files within a folder that has been modified within the last 7 days, i thought this was going to be easy using some kind of switch that looks at the modified date but that doesn't seem to exist and i can't...
General Discussion
How to create a batch file that will move files based on the file type
How to create a batch file that will move files based on the file type? My Requirement : I need a batch file to copy all .doc files in all my HardDisk to a removable disk say (Z: drive) . Can anyone make it possible using a batch file?Please...Its urgent...
General Discussion


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 21:30.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App