将特定文件批量复制到子文件夹中 [英] Copy specific files into subfolder in batch
问题描述
我有一个Windows批处理文件,我正在运行将特定文件移动到子文件夹。
I have a Windows Batch file that I'm running to move specific files into a subfolder.
@ECHO OFF
ECHO Start Copy
setlocal enabledelayedexpansion
set SOURCE_DIR=C:\Users\paul.ikeda\Support\SNDataDemo91\SolidCAD\Inventor_in
set DEST_DIR=C:\Users\paul.ikeda\Support\SNDataDemo91\SolidCAD\Inventor_in\Files to Import
set FILENAMES_TO_COPY=SN_Router_1.ipt SN_Router_2.ipt SN_Router_3.ipt
for /R "%SOURCE_DIR%" %%F IN (%FILENAMES_TO_COPY%) do (
if exist "%%F" (
set FILE_DIR=%%~dpF
set FILE_INTERMEDIATE_DIR=!FILE_DIR:%SOURCE_DIR%=!
echo file "%%F"
xcopy /Y "%%F" "%DEST_DIR%!FILE_INTERMEDIATE_DIR!"
)
)
ECHO.
pause
这是将我需要的3个文件复制到子文件夹,并在子文件夹中创建一个子文件夹,将3个文件再次复制到该子文件夹中,并且在原始源文件夹中存在的文件数量重复。我只想复制3个文件复制到目标文件夹,然后停在那里。
This is copying my 3 desired files into the subfolder, but then it keeps going and creates a subfolder in the subfolder, copies the 3 files again into that subsubfolder, and it's repeating for as many files are in the original source folder. I just want to copy the 3 files to copy to the destination folder and stop there.
任何人都可以发现问题?
Can anyone spot the problem? I don't know enough batch code to properly debug this.
推荐答案
如果你只想复制文件,那么这可能适合您:
If you just want to copy the files then this may suit you:
@ECHO OFF
ECHO Start Copy
set "SOURCE_DIR=C:\Users\paul.ikeda\Support\SNDataDemo91\SolidCAD\Inventor_in"
set "DEST_DIR=C:\Users\paul.ikeda\Support\SNDataDemo91\SolidCAD\Inventor_in\Files to Import"
set "FILENAMES_TO_COPY=SN_Router_1.ipt SN_Router_2.ipt SN_Router_3.ipt"
pushd "%SOURCE_DIR%"
for %%F IN (%FILENAMES_TO_COPY%) do (
echo file "%%F"
xcopy /Y "%%F" "%DEST_DIR%\"
)
popd
ECHO. done
pause
这篇关于将特定文件批量复制到子文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!