Reputation: 1135
I need to copy a set of files mentioned in the loop to another location with each file copied into a directory that is named after the file name.
Example : I need to copy file1.txt from path ABC to DEF\file1\ ; file2.txt from path ABC to DEF\file2\
I have been trying to use this following for loop to achieve the same thing. however there seems to be a syntax error with what I am doing. because of the hurry to deliver this, I could not explore much before posting it here. I am searching for solutions in parallel. Please let me know the issue with the code sample below
FOR %%file IN (de.txt en.txt es.txt fr.txt it.txt ja.txt nl.txt pt.txt zh_CN.txt) DO
SET name=%file%.*
echo f | xcopy /I /Y "C:\textfiles\%name%.txt" D:\textfiles\%name%\LanguageFile.txt
DONE
Upvotes: 1
Views: 143
Reputation: 79983
@ECHO OFF
SETLOCAL
FOR %%f IN (de.txt en.txt es.txt fr.txt it.txt ja.txt nl.txt pt.txt zh_CN.txt) DO (
ECHO ECHO f bar xcopy /I /Y "C:\textfiles\*%%f*" u:\textfiles\%%~nf\LanguageFile.txt
)
GOTO :EOF
Simply echo
es the command to be executed. If correct, change ECHO f bar
to f|
to actually copy
Upvotes: 0
Reputation: 65476
Try this from the command line
for %f in (de.txt en.txt es.txt fr.txt it.txt ja.txt nl.txt pt.mo zh_CN.txt) do echo xcopy "C:\textfiles\%~nf.mo" "D:\textfiles\%~nf\%~nf.mo"
or in batch file
for %%f in (de.txt en.txt es.txt fr.txt it.txt ja.txt nl.txt pt.mo zh_CN.txt) do echo xcopy "C:\textfiles\%%~nf.mo% "D:\textfiles\%%~nf\%%~nf.mo"
Upvotes: 3