I'm trying to create a bat files we can use daily to copy or move PDF files from subfolders (names of folder vary daily) to the parent folder. I have tried the below:
First tried to just copy the files using this..didn't work
copy "Y:\Print OPS\Annuity Ops\*\*.pdf" "Y:\Print OPS\Annuity Ops"
Next I tried to make a list of the files to be copied and use that to copy them, the list is created by the files aren't copied.
Echo %date% Sweep Time = %time% File count = %cnt% > 000_testpdf.txt
echo.>>000_testpdf.txt
dir /b /s *.pdf, /O:N >> 000_testpdf.txt
set logfile=MSOffice_PDF.log
dir /b /s *.pdf, > 000_testpdf.txt
for /f "delims=" %%i in (000_testpdf.txt) do echo D|xcopy "Y:\Print OPS\Annuity Ops\%%i" "Y:\Print OPS\Annuity Ops%%i" /i /z /y
Answer
v - disallowed
copy "Y:\Print OPS\Annuity Ops\*\*.pdf" "Y:\Print OPS\Annuity Ops"
^ allowed
Wild characters *
are allowed only in last part of a path in Windows. Next code snippet could help:
@ECHO OFF
SETLOCAL EnableExtensions
set "_parent=Y:\Print OPS\Annuity Ops"
for /D %%G in ("%_parent%\*") do (
if exist "%%~G\*.pdf" (
echo copy /B "%%~G\*.pdf" "%_parent%\"
) else (
echo nothig to copy "%%~G\*.pdf" "%_parent%\"
)
)
Note that above code merely displays commands to perform for debugging purposes. Replace echo copy /B
with operational copy /B
no sooner than debugged. You could also remove all else
branch.
Resources (required reading):
No comments:
Post a Comment