Page 1 of 1

search - copy problem

Posted: 09 May 2019 08:11
by rusty83
Hello!

I get a Text-file from an system - in this file there are filenames (per line one filename) - now with a batch-file every line (filename) from this list should be searched in a directory and copied in an other direcory.

I have this found and it almost works:

Code: Select all

@echo off &setlocal
set "sourceRoot=C:\Users\test\Desktop\COPY_TEST\originale"
set "sourceList=C:\Users\test\Desktop\COPY_TEST\DBLIST.TXT"
set "destFolder=C:\Users\test\Desktop\COPY_TEST\kopiert"

for /f "delim=" %%i in ('dir /a-d /b /s "%sourceRoot%\*.pdf"^|findstr /ig:"%sourceList%"') do (
  copy "%%~i" "%destFolder%\"
)
ECHO "Ausgabe abgeschlossen"
PAUSE
This works if the list lokks like this:
filename1
filename2
....

BUT from the other system i get the list like this:
filename1;
filename2;
....

OR I can also change it to this:
"filename1"
"filename2"
....

Can someone help me please with this?

Re: search - copy problem

Posted: 09 May 2019 10:14
by aGerman
Untested:

Code: Select all

for /f "usebackq delims=;" %%i in ("%sourceList%") do (
  for /f "delims=" %%j in ('2^>nul dir /a-d /b /s "%sourceRoot%\%%~i"') do copy "%%~j" "%destFolder%\"
)
That will fail if one of the file names contains a semicolon though.

Steffen

Re: search - copy problem

Posted: 09 May 2019 23:36
by rusty83
Hello!

Thank you for your replay!

I tested it but it doesn't work BUT with my function it works now i got a way to export the data in the correct form.

But now I have an additional question:
Is it possible if the search term in the list is for example "file_001;" to replace the last character ";" with a specific termn like "_DE" - so the search term will be "file_001_DE"?
Not the list should be changed only the search term.

Many thanks in advance!

Re: search - copy problem

Posted: 10 May 2019 09:44
by aGerman
It isn't possible as long as you use the /g switch of findstr. Either you have to process your list line by line or you have to change the content of your list before you use it along with findstr /g.

Steffen

Re: search - copy problem

Posted: 12 May 2019 23:02
by rusty83
Thank you for your answer - i changed my version to following one and it works for me :)

Code: Select all

@echo off &setlocal
set "sourceRoot=C:\Users\offic\Desktop\COPY_TEST\originale"
set "sourceList=C:\Users\offic\Desktop\COPY_TEST\DBLIST.TXT"
set "destFolder=C:\Users\offic\Desktop\COPY_TEST\kopiert"
set "sprache=_EN"

FOR /f "tokens=1 delims=;" %%i IN ('FINDSTR . "%sourceList%"') DO (
    copy "%sourceRoot%\%%~i%sprache%.pdf" "%destFolder%\"
)

ECHO "Ausgabe abgeschlossen"
PAUSE