search & copy files from reference list in a text document

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jamesfui
Posts: 50
Joined: 27 Mar 2010 23:00

search & copy files from reference list in a text document

#1 Post by jamesfui » 27 Mar 2010 23:32

Hi Dostips Batch Scripters, the batch process runs like below;

The bat will search through a Reference list(filename1.jpg, filename2.txt, ..etc)
from a text document(ex. ref.txt). then it will Loop copy all those files to each desire folders if the search of these files Exist in certain folders&subfolders.
If possible, it will list out the filenames which does not exist into notexist.txt :?

Do anyone know how to handle script like above??
Thanks. :D

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: search & copy files from reference list in a text docume

#2 Post by aGerman » 28 Mar 2010 07:48

Untested:

Code: Select all

@echo off &setlocal
for /f "usebackq delims=" %%a in ("ex. ref.txt") do set "fullname=%%a" &set "name=%%~nxa" &call :process
pause
goto :eof

:process
if not exist "%fullname%" (
  >>"notexist.txt" echo "%fullname%"
) else (
  copy "%fullname%" "c:\somewhere\%name%"
)
goto :eof


Regards
aGerman

jamesfui
Posts: 50
Joined: 27 Mar 2010 23:00

Re: search & copy files from reference list in a text docume

#3 Post by jamesfui » 29 Mar 2010 04:28

Hi. i tried out your batch script & it works well.. :D thanks

But for example, i do not know where the files are located..
probably in d: drive, in a folder, then a subfolder, another subfolders, etc..

all i got is the (file1.doc, file2.pdf, etc) from the reference list in (ref.txt)
it will not works when there is no Full Path given..

So can this batch file add in a Search features to solve this problems?
:wink: thanks!

Post Reply