Batch to find and copy from namelist.txt

July 21, 2010 at 22:10:14
Specs: Windows XP, Core duo/2 gb
Hi...
I have found similar questions answered, but none that match what I need..
I need a batch file to search all the files contained in a list saved as a text file (D:\data\namelist.txt), and then copy those files to spesific directory..
hoping someone can help me..

This is an example of the existing names in the namelist.txt :
Aralnurin Tyiarinu
Aralstip Yaduedeu
Eudainudru Aedue Saelo
Risur Yanaria
Aisursu
etc

Source folder to search :
D:\data\original

Destination folder :
D:\data\copy

Any help would be appreciated
Thanks


See More: Batch to find and copy from namelist.txt

Report •

#1
July 22, 2010 at 03:40:16
@echo off > nocopy.log & setlocal enabledelayedexpansion
pushd d:\data
for /f "tokens=*" %%a in (namelist.txt) do (
copy "d:\data\original\%%a" "d:\data\copy\%%a" || >> nocopy.log echo %%a
)
::------------ end
if you don't need recursive seach...

Report •

#2
July 22, 2010 at 04:46:44
thank you for the answer @nbrane :)
I have copy and paste this script in notepad, then I save as to search.bat.
but when i run the batch, is not working properly .. the file is not copied at all ... and then only appear notepad (namelist.txt) ..
whether my fault?
Which folder should I put it namelist.txt and search.bat?

Report •

#3
July 22, 2010 at 23:02:54
my apologies. I messed up the syntax in the main loop. The
single quotes should not be there. change this:
for /f "tokens=*" %%a in ('namelist.txt') do (
---
to this:
for /f "tokens=*" %%a in (namelist.txt) do (
-----
(ie: remove single quotes surrounding "namelist.txt").
see also: i edited my response above to reflect this fix.

Report •

Related Solutions

#4
July 22, 2010 at 23:22:07
thank for your response :)
but still not working..the file is not copied
============================
correction :
for /f "tokens=*" %%a in (namelist.txt) do (
copy "d:\data\original\%%a" "d:\data\copy\%%a" || >> nocopy.log echo %%a
)
::------------ end
=============================
This is the result from cmd.exe :
D:data><copy "d:data\original\Yo check It Out" "d:data\copy\Yo check It Out"
|| echo Yo check It Out 1>>nocopy.log >
=============================
And this is the contents of the file that was created (nocopy.txt)
Aralnurin Tyiarinu
Aralstip Yaduedeu
Eudainudru Aedue Saelo
Risur Yanaria
Aisursu
etc
=============================

what should i do? this is correct?


Report •

#5
July 24, 2010 at 09:14:13
only thing i know to try, add this as second line of script:
pushd d:\data

i don't know where "yo check it out" is coming from.


Report •

Ask Question