Solved batch copy specific filenames to another folder

January 3, 2013 at 15:00:13
Specs: Windows 7
i have a folder with around 200,000 image files, from which i want to copy around 20,000 of these , all with unique filenames. is there a program or batch process that can manage the list of files to be extracted in a text file format?

See More: batch copy specific filenames to another folder

Report •

✔ Best Answer
January 6, 2013 at 18:31:11
Ok, I think you've hit on the issue (smacking my palm against my forehead for me being so dumb). The filenames in artimages.txt do not include a drive or path. You can easily provide that in the batch (lets go ahead and code it instead of commandline, to save lots of repetitive typing etc.) Just put the path in front of the filename:
@echo off & setlocal
:: assuming this is where they are, if not, adjust as needed:
set location=C:\Users\Windows7\Desktop\betterbuynow\betterbuynow\images
for /f "tokens=*" %%a in (%location%\artimages.txt) do (
copy "%location%\%%a" c:\artimages
pause
)
::end batchscript
notice that you must have two percents on your "a" variable, not just one. "artimages.txt" can reside anywhere, as long as you give the complete path to it. If the location I used is not right, or differs between the two instances (inside, then outside the parentheses), just make sure it is correct for both applications (location of "artimages.txt", location of images). I hope this gets you going, and i apologize for being such a dummy about the path issue. I should have figured that out about 9 or 10 replies ago. :-(


#1
January 3, 2013 at 17:35:56
Do you mean you have a textfile with the names of the files you want to copy? If so, and of the format is one filename per line, this might:

for /f "tokens=*" %%a in (copyfilz.txt) do @copy "%%a" c:\x\destination

If not, maybe a little more detailed description to help those of us who are "challenged". ;-)


Report •

#2
January 3, 2013 at 17:42:35
thank you for the reply, yhes each filename is on a separate line within the textfile. example below

000bfd7bae93ad35f6f4fad38e365f43.image.405x340.jpg
001e17a8f441c78f009a518aebd11859.image.333x340.jpg
002041874c4d2b5c478c2062a29ea58e.image.213x340.jpg
0048db4ac8068c0b40bf2a485b6bdda5.image.400x340.jpg
00684bcaeed4ad8c39194e25502e1599.image.255x340.jpg
00757af2fba35562bd311f57b174dd14.image.268x340.jpg
01e702d943c41cf09ed2cd449387fed1.image.265x340.jpg
022cde1e55bbeda341c939c8065a12f1.image.254x340.jpg
02ec21b32daed5f79f39061c83d56d96.image.391x340.jpg
0306221fe888a96223b5d63f2c5f3adc.image.238x340.jpg
0397096c7fa4171e8155b40380873f95.image.450x288.jpg
039aa236ef926dd673c2db2d9757f10d.image.431x340.jpg
03dd71203189cbcb6d63e0b1756a8785.image.280x340.jpg
03e238352251df6ecb173e42c7556f91.image.450x270.jpg
0432d9d124e5ff0111344a795c2693bd.image.450x334.jpg
04603a4f12314158e397fc20e0c13e00.image.416x340.jpg
0478df552fa77f76b22f4961b38992c4.image.450x335.jpg
04fe4e2f6e3bf0845dca5539df32a798.image.240x340.jpg
0517c651fde64c774d676fb92bc06239.image.448x340.jpg


Report •

#3
January 3, 2013 at 17:56:59
What I posted should work then, but to cut down on verbosity:
@for /f "tokens=*" %%a in (copyfilz.txt) do @copy "%%a" c:\x\destination > nul

ps: if you run it from commandline, make each %% into just one %


Report •

Related Solutions

#4
January 4, 2013 at 14:30:50
@for /f "tokens=*" %a in (c:\users\windows7\desktop\betterbuynow\betterbuynow\images\artimages.txt) do @copy "%a" c:\artimages > nul

run from command line seems to do something as i can see the images inside the folder moving abou?, but cannot find where the new copied images would be stored. i assume they should be in c:\artimages folder, but folder doesn't seem to exist.

any ideas what i am doing wrong?
i did a basic search for one of the image files within the txt file, and the image no longer appears to be in the original folder either?


Report •

#5
January 4, 2013 at 14:49:15
Make sure this path exists before you do the copy:

c:\artimages

Tony


Report •

#6
January 4, 2013 at 15:04:28
mmmm. nothing, and indeed, all of the original images in the master folder no longer seem to be there?

Report •

#7
January 4, 2013 at 19:19:12
Oh, sh_t. One of the few times I post code unsafetied...
Tony is right, I neglected to create the target directory before copying.
The "copy" should not have removed the files from the original directory, since I did not use "move" and no deletion took place. Since apparently "c:\artimages" did not exist, then the copy would have either hung, waiting for you to answer "y/n" to the (invisible) query "overwrite existing file c:\art?" (because copy interprets "c:\artimages" as a file since the directory does not exist, and each file in the master-list is trying to be copied to that same file) OR, on win-7, it might have gotten "access denied" error.
Well, those are the explanations of what went wrong, but I can't say why the files are not still residing in the original directory, and also why the copy did not abort one way or the other. I ran a sim on win-7 just to make sure, and this should not have happened using the given code. (hint to Someone Smarter Than Me: just what really happened here?)
Try damage-control: go to c:\ (root of drive), and try "dir /s /p *.jpg" and see what comes up. (You might need to filter it: dir /s /p 0*.jpg, or dir /s /p 0*340.jpg)
At this point I'm clueless and waiting for the scarecrow to bring me some weed. :-(



Report •

#8
January 6, 2013 at 13:33:55
thanks for the reply. tried it with directory created, still nothing, even tried with new lpg filenames that i know are in the directory, still nothing. command line flicks as if it is doing something, but still no result?

Report •

#9
January 6, 2013 at 14:19:02
Try it in "verbose"/debug (pause) mode to see what's going on:

for /f "tokens=*" %a in (c:\users\windows7\desktop\betterbuynow\betterbuynow\images\artimages.txt) do copy "%a" c:\artimages & pause


Report •

#10
January 6, 2013 at 16:04:19
do the images i am trying to copy, have to be in the same directory as the text file that lists the images?

Report •

#11
January 6, 2013 at 16:30:11
i even simplified my text file down to one single image file name which i knew did exist inside the directory i have the 'artimages.txt' file, and it still could not find it?

for /f "tokens=*" %a in (C:\Users\Windows7\Desktop\betterbuynow\betterbuynow\images\artimages.txt) do copy "%a" c:\artimages & pause

so it definately finding the directory to reacd the text file, finding the text file and reporting 'the system cannot find the specific file' and stopping.

simulte this on your own desktop with your own file and check if it works, just not getting any joy here.

i do appreciate the help you are giving, as this, if it works, will save me a lifetime of tears


Report •

#12
January 6, 2013 at 18:31:11
✔ Best Answer
Ok, I think you've hit on the issue (smacking my palm against my forehead for me being so dumb). The filenames in artimages.txt do not include a drive or path. You can easily provide that in the batch (lets go ahead and code it instead of commandline, to save lots of repetitive typing etc.) Just put the path in front of the filename:
@echo off & setlocal
:: assuming this is where they are, if not, adjust as needed:
set location=C:\Users\Windows7\Desktop\betterbuynow\betterbuynow\images
for /f "tokens=*" %%a in (%location%\artimages.txt) do (
copy "%location%\%%a" c:\artimages
pause
)
::end batchscript
notice that you must have two percents on your "a" variable, not just one. "artimages.txt" can reside anywhere, as long as you give the complete path to it. If the location I used is not right, or differs between the two instances (inside, then outside the parentheses), just make sure it is correct for both applications (location of "artimages.txt", location of images). I hope this gets you going, and i apologize for being such a dummy about the path issue. I should have figured that out about 9 or 10 replies ago. :-(

Report •

#13
January 7, 2013 at 17:09:47
ok, made that .bat file up, ran the first test on the single image file in the txt file, and yeah, it all worked. soo, soo, thankful for your perserverence in getting this working fro me.

thank you
mark


Report •

Ask Question