Saturday, November 6, 2010

A Specialized Batch File

This batch is of limited use, but I am archiving it here because there may be code snippets that may be cannibalized in the future for other batch files.

@echo off
cls
set error=0
cd\newdir
if exist parse.txt del parse.txt
dir "\newdir" /b /a-d > temp.txt
if not exist temp.txt echo No files found!
if not exist temp.txt pause
if not exist temp.txt exit
echo Temporary file has been created.

rem -----------------------------------------------------
rem The following FOR statement must be one line, not two
rem (Beware of Blogger's word wrap.)
rem -----------------------------------------------------
FOR /F "usebackq tokens=* delims=" %%a in (temp.txt) DO call :process "%%a"
rem -----------------------------------------------------
echo.
echo Alas, We Have Reached The End.
echo Errors: %error%
echo.
pause
exit

:process
rem echo 1 %1 2 %2 3 %3 4 %4 5 %5
rem pause

set VAR1=%1
rem Trim quotes
for /f "useback tokens=*" %%a in ('%VAR1%') do set VAR1=%%~a
rem echo VAR1=%VAR1%

rem determine length of filename. if less than five, skip.
set filename=%VAR1%
set #=%filename%
set length=0
:loop
if defined # set #=%#:~1%
if defined # set /A length += 1
if defined # goto loop
rem if %my-number% gtr 10
rem echo %filename% has a length of %length%
if %length% lss 5 echo skipping %filename%!
if %length% lss 5 goto :EOF

echo filename=%filename%
rem pause
if not exist "pictext\%filename%" echo ******************************************where is pictext\%filename% ?
if not exist "pictext\%filename%" set /A error+=1
if not exist "pictext\%filename%" echo %2,%3,%4
if not exist "pictext\%filename%" pause
if not exist "pictext\%filename%" goto :EOF

if not exist "trees\%filename%" echo %filename% not found in trees!
if not exist "trees\%filename%" pause
if not exist "trees\%filename%" goto :EOF

rem set caption=
rem FOR /F "usebackq tokens=* delims=" %%a in ("pictext\%filename%") do set caption=%%a
rem set /p caption=<"pictext\%filename%"
type "pictext\%filename%" >> parse.txt
rem echo %caption%@%filename%
echo @%filename%>>parse.txt
goto :EOF
by igor 04:20 4 replies by igor 09:32 0 comments

No comments:

techlorebyigor is my personal journal for ideas & opinions