Copy files from a list of filenames

January 25, 2010 at 07:14:39
Specs: Windows XP
Hello,

I have a hard drive which contains over 200,000 jpeg and eps files. I also have a list with around 2000 filenames of files that I need to copy from the hard-drive to another folder.

Is there a program I can use that will read the list of filenames and copy only the files in that list to another folder?

I have looked into using command prompt to achieve this. I know it's possible, however I am a complete beginner when it comes to this and would greatly appreciate if someone could explain the process to me in layman's terms.

Many thanks in advnce,

Johnnie


See More: Copy files from a list of filenames

Report •

#1
January 25, 2010 at 07:23:42
It can be done. At the Command Prompt, type
FOR /?

to find out how. Or you could give us some more details and specifics, and we'll throw something together.

Report •

#2
January 25, 2010 at 07:31:45
We need to see a sample of your files list. If you could post like the first 5 lines of your file list. Also, what is the name of the file that you have your list in? (i.e. filelist.txt) And last, where is your file list stored on your hard drive?

"I need to copy from the hard-drive to another folder"

Where are the files located on your hard drive and where is this destination folder? Is it on the same drive or a different drive?

We need these details before we can help.


Report •

#3
January 25, 2010 at 07:42:56
Thanks for the quick reply Razor. I have had a look at the FOR /? and have been left slightly light headed!

Basically I have a .txt file with 2000 filenames made up of letters and numbers (no spaces). I want to use this list of filenames to copy files from a hard-drive (F:) into a separate folder on say my C: drive. The files on the hard-drive are separated into various folders.

Please let me know if I can provide you with any more information that will make things more clear.

Thanks.


Report •

Related Solutions

#4
January 25, 2010 at 07:53:04
Where on the C: Drive do you want to place them?
Can you copy an paste a sample of your file list?

Report •

#5
January 25, 2010 at 07:57:56
Hi ace_omega thanks very much for your reply.

Here are a few examples of the filenames in my list. Some contain a hyphon as you can see from the last code.

02A15DYW
02A15TR4
02A16R2W
02A16R2X
02A1-6M0D

My list.txt is saved as C:\list.txt

The files are stored in numerous folders within a hard drive on F:\ called Images; F:\Images

Ideally I would like to copy the files into a new folder on C: say: C:\Selection

Many thanks, please let me know if I can provide you with any further information.


Report •

#6
January 25, 2010 at 08:19:35
Untested (script version):
for /f "delims=" %%a in (c:\list.txt) do for /r %%b in ("f:\images\%%a*") do copy "%%~Fb" c:\Selection

EDIT: Fixed typo.


Report •

#7
January 25, 2010 at 09:06:52
Hi Razor. I navigated to the F: drive (cd F:) and then copy and pasted your script and got the message below:


%%a was unexpected at this time


I also tried pasting the script within C: and Z: and the same message came up.

Any ideas?


Report •

#8
January 25, 2010 at 09:19:49
That was the script version, not the command line version.

That version looks like this (still untested):

for /f "delims=" %a in (c:\list.txt) do for /r %b in ("f:\images\%a*") do copy "%~Fb" c:\Selection


Report •

#9
January 25, 2010 at 09:30:58
As I mentioned previously I am a complete beginner with scripts and dos so apologies for my lack of knowledge!

I have tried pasting the above into command prompt and nothing seems to happen when I hit enter. I have checked the C:\Selection folder and it's empty.

I would greatly appreciate it if you could explain to me how best to apply this command line or the previous script version.

Thanks.


Report •

#10
January 25, 2010 at 09:43:41
Well, teach me to try to answer a question while eating lunch:
for /f "delims=" %a in (c:\list.txt) do for /r "f:\images" %b in ("%a*") do copy "%~Fb" c:\Selection

Really, FOR /R doesn't work the way anyone thinks it should.

Report •

#11
January 25, 2010 at 09:52:13
Thanks Razor I appreciate your help.

I'm still not having much joy here; when I paste the above into command prompt nothing (from what I can see) is happening. There are no images in C:\Selection

I have also tried separating the filesnames by commas (replacing ^p with ,) but this doesn't make any difference.


Report •

#12
January 25, 2010 at 10:06:52
I'm still not having much joy here
I've tested the above; it works on my (locked down XP Pro) system. Perhaps there's something else going on? I donno. (Does the list match up exactly to the file names, or only "kinda-sorta"?)

I have also tried separating the filesnames by commas (replacing ^p with ,) but this doesn't make any difference.
No, that'd make the problem harder.


Report •

#13
January 25, 2010 at 10:12:06
The list matches - there are no files in the list which are not on the hard drive.

In theory should I just be able to copy and paste your command line and it should work - or is there anything else i should be entering?

Thanks.


Report •

#14
January 25, 2010 at 11:14:04
Should just be copy/paste. The line doesn't even assume your working directory.

Report •

#15
January 26, 2010 at 01:28:17
Thanks for your help Razor, although I still can't seem to get this working.

Could anyone suggest what I might be doing wrong here - or offer any other possible solutions.

Any help much appreciated.


Report •

#16
January 26, 2010 at 12:15:51
well, the suggestion i have is to paste the script into a batchfile instead of commandline, so you have more control
(echos, pauses, etc).
maybe try a reversed rendition of Razors script (it should work either way, i think, but like Razor said, the FOR /R is not always intuitive in its behavior).

@echo off & setlocal
:first, make sure the dest directory exists!
md c:\selection 2>nul
cd f:\images
for /r %%a in (.) do (
for /f %%b in (c:\list.txt) do (
copy "%%b" c:\Selection
)
)

past this into a script, not to the commandprompt:
select from "@echo off" down to the final parenthesis,
ctrl-c
open notepad
ctrl-v
alt-f and save the script as:
c:\getjpg.bat
then at commandprompt:
cd c:\
get.jpg

i left the output from copy going to the screen, so it will look ugly, but just let it run and see what you get in c:\selection.
i have a feeling this is not the best way to go about this - it has to scan the list for each subirectory in the whole tree from root f:\images, but it appears you won't be running more than once anyhow. the other way is for each element in list, go throught the whole tree...
follow up with a post to let us know what transpired...


Report •

Ask Question