I have Folder A with multiple pdf files named:
FL001.pdf
FL002.pdf
FL003.pdf
etc.
And a Folder B with subdirectories that contain other folders named after the files in Folder A that contains other .pdf files, like this:
FL000-099
FL001
- 001100.pdf
- 001101.pdf
FL002
- 002100.pdf
- 002101.pdf
FL003
- 003100.pdf
- 003101.pdf
FL100-199
FL101
- 101100.pdf
- 101101.pdf
FL102
- 102100.pdf
- 102101.pdf
F3003
- 103100.pdf
- 103101.pdf
etc.
And I also have a network printer.
What I'm trying to do:
By following the names of the .pdf files in Folder A search the corresponding subdirectories in Folder B; IF exists then send to the printer the .pdf file from Folder A and then send to the printer all the .pdf files in the corresponding subdirectory from Folder B, then go to the next file and repeat the process for all the names/files in Folder A.
Printing the .pdf's in Folder A is ok, but I need help for the second part which is not working. If I change the current_directory
to ...\Folder B\FL000-099\
it works, but I need to search in all subdirectories from the original path. (see code below)
What I have done
@echo off
set current_directory=C:\Users\user\Desktop\Folder B\
set art_directory=C:\Users\user\Desktop\Folder A\
set filename=FL001
set extension=.pdf
set tofind=%current_directory%%filename%
set tofind2=%art_directory%%filename%
set tofindextension=%tofind2%%extension%
IF EXIST %tofindextension% ( "C:\Program Files\SumatraPDF\SumatraPDF.exe" %tofindextension% -print-to "\\server\printer"
) ELSE (
echo "No file!"
)
IF EXIST %tofind%\ (
FOR /R %tofind% %%F in (*.pdf*) do "C:\Program Files\SumatraPDF\SumatraPDF.exe" %tofind%\%%~nxF -print-to "\\server\printer"
) ELSE (
echo "No file!"
)
pause
Is it possible to search as described above? Can you help me with a solution?