Page 1 of 1

search & copy files from reference list in a text document

Posted: 27 Mar 2010 23:32
by jamesfui
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

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

Posted: 28 Mar 2010 07:48
by aGerman
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

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

Posted: 29 Mar 2010 04:28
by jamesfui
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!