foxidrive wrote:
I learned to read with comics. It was a great way to get kids to read.
I grew up a God fearing Catholic. Lots of Old and New Testament. For fun I got to read and color in my Mom's human anatomy books.
Moderator: DosItHelp
foxidrive wrote:
I learned to read with comics. It was a great way to get kids to read.
dchall8 wrote:It is working nicely. Thank you so much.
What do I need to change to use a 5-digit page number?
Code: Select all
set "pagenum=!pagenum:~4!"
My hobby is writing about lawn care with a specialty in organic lawn care. If you want to have the nicest lawn on the block, or on the planet, or even if you just want nicer looking weeds, I can set you up.
squashman wrote:For fun I got to read and color in my Mom's human anatomy books.
dchall8 wrote:In looking at the code, I think I see where you use the md command to create a dst directory, but I don't see the dst directory anywhere. The files are pouring into the Destination folder.
Code: Select all
:: Prevent these commands from being displayed while the batch file is running
:: Enable command processor extensions to ensure that for is able to use the /f switch
:: Enable delayed environment variable expansion so that variables will update inside of loops properly
:: Starting batch scripts with this line is not always necessary, but generally encouraged
@echo off & setlocal EnableExtensions EnableDelayedExpansion
:: Make a backup of the current PATH variable
set "oldpath=%PATH%"
:: Add C:\bin to the PATH so that you don't need to write C:\bin\tiffcp every time
set "PATH=%PATH%;c:\bin;"
:: Source location for the original files
:: %userprofile% is a short way of saying C:\Users\<your username>
set "SRC=%userprofile%\documents\Orginal Deeds"
:: Destination location for the PDF files (DST)
set "DST=c:\Destination"
:: Create the directory C:\Destination
:: 2>nul prevents any error messages from appearing on the screen during this
md "%dst%" 2>nul
:: Commands are only echoed until %DEB% ist set to nothing - this is broken
set DBG=ECHO/
::set "DBG="
:: Go into the directory indicated by the %SRC% variable
:: pushd keeps track of the directory you were just in so you can immediately return to it
pushd "%SRC%"
:: for /f processes the output of the command in parentheses line by line
:: "delims=" means each line gets process as a single string instead of being broken up by delimiters
:: %%z is the variable that the current line gets stored to
:: /b will make the dir command return nothing but names of files and folders
:: /s will recursively search any folders that are currently inside the directory
:: /ad will make dir only return folders
for /f "delims=" %%z in ('dir /b /s /ad') do (
REM Go to the directory indicated by %%z
REM Also, I've switched from double colons to REM because the two colons is technically a line label
REM and line labels don't play nice with for loops for me even though other people have had luck
pushd "%%z"
REM If any files with the 001 extension exist...
if exist *.001 (
REM Process the list of all files with the 001 extension one file at a time, storing each filename in %%A
REM /a-d will make dir return everything in the folder that isn't another folder
REM /ONE is short for /ON /OE and sorts the files alphabetically first by name and then extension
for /F "delims=" %%A in ('dir /B/A-D/ONE "*.001"') do (
REM Set pagenum to %%A, using ~n to ensure that only the filename and not part of the path is included in the variable value
set "pagenum=%%~nA"
REM Remove all but the four leftmost characters of pagenum
set "pagenum=!pagenum:~4!"
REM Empty the PG variable
set "PG="
REM Take the list of files whose names are all %%A and create one long string containing all of those files
REM ~n
for /F "delims=" %%B in ('dir /B/A-D/ONE "%%~nA.*"') do set PG=!PG! %%~nxB
REM Concatenate the files into the Source folder with a .TIF extension
tiffcp -c lzw !PG! %%~nA.TIF
REM Convert the TIF file to a PDF
tiff2pdf -o "%dst%\Volume %%~nxz page !pagenum!.pdf" %%~nA.TIF
REM Delete the TIF files
DEL %%~nA.TIF
)
REM Wait until the user presses the enter key
pause
)
REM Return to the directory that you were in before you went into %%z
popd
)
:: Return to the directory that you were in before you went into %SRC%
POPD
:: Reset the path to the original path
set "PATH=%oldpath%"
:: Note that you don't have to use the exit command to stop the script
:: Since there is nothing left for the script to do, the program ends naturally
ShadowThief wrote:I hope foxidrive doesn't mind that I've taken the liberty of commenting his code...
dchall8 wrote:No new folders (directories) are being created. The files are going into the Destination folder (directory).
foxidrive wrote:dchall8 wrote:I suppose it is not critical to recreate the original folder structure, but the naming convention already in use makes it easy to find these files.
The PDF files can all go into a single folder in c:\ so that makes it a simpler script