Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
rusty83
- Posts: 3
- Joined: 09 May 2019 08:02
#1
Post
by rusty83 » 09 May 2019 08:11
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?
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 09 May 2019 10:14
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
-
rusty83
- Posts: 3
- Joined: 09 May 2019 08:02
#3
Post
by rusty83 » 09 May 2019 23:36
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!
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#4
Post
by aGerman » 10 May 2019 09:44
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
-
rusty83
- Posts: 3
- Joined: 09 May 2019 08:02
#5
Post
by rusty83 » 12 May 2019 23:02
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