准备好放弃这一次了。*(可接受任何新的想法或调整。
我有一个.txt文件列出了.pdf文件。不Path..just文件名。对于每个.pdf,请查看源文件夹**和子目录中的匹配。如果找到匹配,将.pdf复制到目标文件夹。**源文件夹中的某些子目录在名称中有空格。
我的脚本:
for /f %%i in (File-List.txt) do echo F| xcopy "C:\Source_Folder\%%i" "c:\Target\%%i" /i /z /y结果:,它正在查找.pdf文件,但只搜索源目录中的第一个目录,即子目录?
发布于 2016-01-19 06:14:19
@ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir"
SET "targetdir=U:\destdir"
FOR /f %%a IN ("%sourcedir%") DO SET "drive=%%~da"
for /f "delims=" %%i in (q34868638.txt) do (
REM attrib /s "%sourcedir%\%%i"
FOR /f "tokens=1*delims=:" %%a IN ('attrib /s "%sourcedir%\%%i"') DO (
IF "%%a"=="File not found - %drive:~0,1%" (ECHO "%%i" NOT found) ELSE (
ECHO copy /b "%drive%%%b" "%targetdir%\"
)
)
)
GOTO :EOF您需要更改sourcedir和targetdir的设置,以适应您的情况。
我使用了一个名为q34868638.txt的文件,其中包含了一些用于测试的数据。您使用的文件名由您决定。
所需的副本命令只是用于测试目的的ECHO编辑。在验证命令是正确的之后,将ECHO(COPY更改为COPY以实际复制文件。附加>nul以抑制报告消息(例如。1 file copied)
发布于 2016-01-19 06:07:59
@echo off
setlocal EnableDelayedExpansion
rem Create a list of subdirectories to search separated by semicolon (like PATH variable)
set "subdirs=C:\Source_Folder"
for /D /R "C:\Source_Folder" %%d in (*) do set "subdirs=!subdirs!;%%d"
rem For each .pdf in the text file
for /F "delims=" %%f in (File-List.txt) do (
rem Look in the list of subdirectories for a match
rem see HELP FOR for further details
for %%p in ("%%f") do set "filePath=%%~$subdirs:p"
rem If match found
if defined filePath (
rem Copy .pdf over to destination folder
copy "!filePath!" "c:\Target"
)
)https://stackoverflow.com/questions/34868638
复制相似问题