Hi,
I want to be able to move selected files from a folder (and hopefully a bunch of subfolders in one directory)
This is what I have in my .bat file:
for /f "delims=" %%i in (TEST.txt) do echo D|xcopy "S:\TEST 1\%%i" "S:\TEST 2\%%i" /i /z /y
My TEST.txt document contains the following information:
1.xlsx
3.xlsx
My files I want to move are in S:\TEST 1 (3 excel files named "1","2" and "3") and i want to move them to S:\TEST 2
It copies the files but creates a new folder for each moved file named "1.xlsx" and "3.xlsx" with the file inside them.
Can somebody help me stop it doing this and just simply place the files into the folder without creating new folders?
Also if somebody knows how to do this on more than one folder at a time so it will find the file in the .txt file in one of 15 subfolders in the same location that would be great.
Kind Regards
Steven
Using the FOR command to copy files listed in a text file
Moderator: DosItHelp
Re: Using the FOR command to copy files listed in a text fil
This has the target %%i folder removed, and a backslash on the end of the target folder to eliminate the need for echo D
You can include the folders in your text file - but more information about what you need to copy is needed to give you specifics.
Code: Select all
for /f "delims=" %%i in (TEST.txt) do xcopy "S:\TEST 1\%%i" "S:\TEST 2\" /i /z /y
You can include the folders in your text file - but more information about what you need to copy is needed to give you specifics.
Re: Using the FOR command to copy files listed in a text fil
The purpose above was just a test to see what can be done, to implement and help us with our work flow.
Currently we have a folder of images, and we have a database in excel listing all of these images with results. So say we want everything that is tagged floral in our database, we may need all of these together to put somewhere, and this allows us to pull them out easily, rather than a human sourcing the files required.
I have made the changes that you mentioned and it works great!
We are very grateful!
One last question is, this currently copy's the items and we sometimes may want to MOVE the files. Can this be tweaked to move?
Thank you
Currently we have a folder of images, and we have a database in excel listing all of these images with results. So say we want everything that is tagged floral in our database, we may need all of these together to put somewhere, and this allows us to pull them out easily, rather than a human sourcing the files required.
I have made the changes that you mentioned and it works great!
We are very grateful!

One last question is, this currently copy's the items and we sometimes may want to MOVE the files. Can this be tweaked to move?
Thank you
Re: Using the FOR command to copy files listed in a text fil
replace xcopy with move and remove the " /i /z /y"