wasabi3689
asked on
how to roll into all sub dirs
I have the following Windows script working fine. there is one issue I want to add.
I have root directory C:\Sample_PDF\, under the root, there are sub diredtories then the files are resided, then I run the .exe, I want program automatically to go into each the sub dir to execute .exe., make the converted files still resided in its original file directories
So, how to modify this code?
I have root directory C:\Sample_PDF\, under the root, there are sub diredtories then the files are resided, then I run the .exe, I want program automatically to go into each the sub dir to execute .exe., make the converted files still resided in its original file directories
So, how to modify this code?
If I understand correctly, this should do the job. It uses a FOR /D to get the folders in the base directory and then processes the matching files in each of those. Output goes to the same folder as the input.
~bp
@echo off
setlocal enabledelayedexpansion
set startTime=%time%
echo Start Time: %startTime%
set SourceDir=C:\Sample_PDF
set FNPattern=*.doc
if not exist "%SourceDir%\" (
echo %~nx0 Missing source folder "%SourceDir%"
exit /b 1
)
for /d %%A in ("%SourceDir%\*.*") do (
for %%a in ("%%~A\%FNPattern%") do (
C:\Sample_PDF\OfficeToPDF.exe "%%~a" "%%~dpna.pdf"
)
)
pause
echo Finish Time: %time%
*EDIT* : Corrected BaseDir name to SourceDir.~bp
Using Bill's code, remove the trailing \ from these. Then it should work.
becomes
set SourceDir=C:\Sample_PDF\
set TargetDir=C:\Sample_PDF\
becomes
set SourceDir=C:\Sample_PDF
set TargetDir=C:\Sample_PDF
ASKER
I don't know the .doc file is not converted. When I run it, I don't see an error, just no output? how to debug it??
ASKER
It looks like there is a bug. For example,
if my root is set to C:\Sample_PDF, but if I have more than 2 sub dirs like
C:\Sample_PDF\ABC\EFG\MMB\ KLJ\file.d oc
The program doesn't work
If my root is set to C:\Sample_PDF\ABC\EFG\MMB, it works.
I want to set the root then go through all sub dirs
Here is the code, how to fix this issue?
if my root is set to C:\Sample_PDF, but if I have more than 2 sub dirs like
C:\Sample_PDF\ABC\EFG\MMB\
The program doesn't work
If my root is set to C:\Sample_PDF\ABC\EFG\MMB,
I want to set the root then go through all sub dirs
Here is the code, how to fix this issue?
@echo off
setlocal enabledelayedexpansion
set startTime=%time%
echo Start Time: %startTime%
set BaseDir=C:\Sample_PDF\PDF
set FNPattern=*.doc
if not exist "%BaseDir%\" (
echo %~nx0 Missing source folder "%BaseDir%"
exit /b 1
)
for /d %%A in ("%BaseDir%\*.*") do (
for %%a in ("%%~A\%FNPattern%") do (
OfficeToPDF.exe "%%~a" "%%~dpna.pdf"
)
)
echo Finish Time: %time%
pause
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
A++++ solution
ASKER
Open in new window