Moving files from a list of filenames in .txt

August 30, 2011 at 14:49:38
Specs: Windows 7
Hi guys, I've searched high and low for something to solve my problem.

I am a photographer and my clients often give me a list of files names, reprint.txt, that they want to print again.
For example, about 300 out of the 600 photos that I gave them.

I have a folder, c:\selected with the 600 photos.
Can I move the 300 files listed in c:\reprint.txt to the new folder, c:\selected2 ?

The files names in c:\selected are like these:
1234.CR2
1235.CR2
1236.CR2

reprint.txt probably contain just the file names (without the extention):
1234
1235
1236

The ideal option is moving the file.
But if it's not possible, copying is fine too.

I really need help here as sometimes the file list goes over a thousand! =/
Thank you guys so much!


See More: Moving files from a list of filenames in .txt

Report •


#1
August 30, 2011 at 16:39:03
Will all of the files just be numbers in the filenames be in sequential order (like 1256, 1257, 1258, ...) or will they be random? Because you could easily use something like this if they are in sequential order:

@ECHO OFF
ECHO Please enter filename starting number:
SET STARTNUM=
SET /P STARTNUM=
CLS
ECHO Please enter filename ending number:
SET ENDNUM=
SET /P ENDNUM=
SET /A STARTNUM=%STARTNUM%
SET /A ENDNUM=%ENDNUM%
MD SELECTED2
SET /A CURNUM=%STARTNUM%
:LOOP
CLS
ECHO Moving files... please wait.
CD SELECTED
MOVE %CURNUM%.CR2 C:\SELECTED2
SET /A CURNUM=%STARTNUM%+1
IF '%CURNUM%'=='%ENDNUM%' GOTO END
GOTO LOOP
:END
CLS
ECHO Files moved.
PAUSE
EXIT

Note that the batch file will need to be saved in the direct C:\ root folder for this to work. Try it out. It won't need the reprint.txt to operate :).

Mouse could not be found. Click OK to continue.
What to do now?


Report •

#2
August 30, 2011 at 16:46:31
Thanks for the reply!
The filenames will not be in sequential order.
Is there a workaround?

Report •

#3
August 30, 2011 at 23:35:22
Is it possible that duplicate filenames (filename only) will exist in C:\Selected e.g. 1234.cs2 and 1234.ab1 (with different extensions)?


Please come back & tell us if your problem is resolved.


Report •

Related Solutions

#4
August 30, 2011 at 23:38:50
Hi Wahine,

Thanks for the reply.

Nope, there is only one copy of each file (one filename).


Report •

#5
September 1, 2011 at 01:36:12
Test this. It will hopefully copy files listed in Reprint.txt from C:\Selected\ to C:\Selected2\. If you are satisfied with the results simply change the command Copy to Move. The script has not been tested. No allowance has been made for a filename which appears in Reprint.txt but which does not exist in C:\Selected\ perhaps due to a typo. Script amended.

Good luck.

@echo off
cls
setlocal

if not exist c:\selected2\ md c:\selected2\

for /f "tokens=*" %%1 in (reprint.txt) do (
    if exist c:\selected\%%1.* (
       copy "c:\selected\%%1.*" "c:\selected2\">nul
       ) else (
         echo Filename %%1 in Reprint.txt not exist in C:\Selected\
    )
 )




Please come back & tell us if your problem is resolved.


Report •


Ask Question