简体   繁体   中英

Copy Files using a batch file

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

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"
@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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM