rem tricks you can play in 4NT rem ----------------------------- rem magic characters (configurable) rem & joins commands, rem ^ is esc char to next char to allow magic chars rem ^ at line end, makes following line as if one with this one. rem > redirect output rem < redirect input rem % macro replacement rem [] function parameters rem @ function name rem ----------------------------- rem get a list of fully qualified directory names in this directory tree, not including . and .. rem note for uses /r for recursive where dir uses /s dir /b /a:d /s rem ----------------------------- rem get a list of fully qualified file names in this directory tree dir /b /a:-d /s rem ----------------------------- rem get a list of fully qualified directory and file names in this directory tree dir /b /s rem ----------------------------- rem capture a list of fully qualified *.html file names in this directory tree dir /b /a:-d /s *.html > temp.txt rem ----------------------------- rem get a files in the java files in current directory in order by date, last modified = newest last dir /b /o:d *.java rem ----------------------------- rem get list of files any of the following attributes: rem R Read-only rem H Hidden rem S System rem A Archive rem D Directory rem E Encrypted rem C Compressed rem I Not content-indexed rem J Junction rem L Symbolic link or Junction rem N Normal (cannot be used for file selection. no other attribs) rem O Offline rem P Sparse file rem T Temporary Rem find files that are hidden AND system AND not compressed dir /b /a:+h+s-c rem ----------------------------- rem delete an entire directory tree, both files and subdirs rem /S=subdir /E=suppress errors /X=delete empty dirs /Y=yes to prompts del E:\stuff /SEXY rem ----------------------------- rem copy just the changed files in a directory tree to a duplicate on another machine. rem XCOPY's intelligence is doing this, not 4NT's. rem /S=subdir /E=copy empty /Y=yes to prompts /D=date newer than target xcopy E:\intellij\*.* \\roedyacer\E\intellij\ /SEYD rem ----------------------------- rem convert all files in the current directory to pure lower case for %i in (*.*) do rename %i %@LOWER[%i] rem ----------------------------- rem for each jar in the directory tree, run jarlook, rem redirecting the output to xxx.look where xxx.jar rem was the name of the jar. for /r %i in (*.jar) do jarlook.exe %i > %@NAME[%i].look rem ----------------------------- rem detect files that have duplicate gif/png versions. for %i in (*.gif) do if exist %@NAME[%i].png echo %i has gif/png duplicates rem other useful functions on filenames: rem @EXT File extension rem @FILENAME File name and extension rem @FULL Full file name with path rem @NAME File name without path or extension rem @PATH File path without name rem @TRUENAME canonical name of a file rem ----------------------------- rem generate a bat file that can later be used to rename files rem chopping off the first 6 chars off each filename empty C:\temp\temp.bat echo generating rename commands in temp.bat for %i in (*.*) do echo rename %i %@instr[6,,%i] >> temp.bat pause echo running rename commands in temp.bat call C:\temp\temp.bat del C:\temp\temp.bat rem ----------------------------- rem compare two directories to see where file lengths have changed for %i in (*.java) do ( set file1=E:\old\jgloss\%i set file2=E:\current\jgloss\%i if not "%@FILESIZE[%file1]" == "%@FILESIZE[%file2]" echo %i ) rem ----------------------------- rem Pick the more compact: the *.jpg or the *.png, delete the bigger one. rem Note no quotes in IF to get a numeric compare rem If .png bigger delete png for %i in (*.png) if exist %@NAME[%i].jpg if %@FILESIZE[%i] GT %@FILESIZE[%@NAME[%i].jpg] del %i rem If .jpg bigger, or equal delete jpg. There is no such thing as as ELSE for %i in (*.png) if exist %@NAME[%i].jpg if %@FILESIZE[%@NAME[%i].jpg] GE %@FILESIZE[%i] del %@NAME[%i].jpg rem ----------------------------- rem run tidy.bat in each of the subdirectories of the E:\com\mindprod tree e: cd E:\com\mindprod rem echo %cd %d shows us that %d gives each directory in the tree rem where %cd gives us its parent. rem /a:d attribute directory, /r recursive, /h hide dots rem Visits directories more than once because of . and .. without /h rem Note that the there is no automatic CD on the discovered directory. for /a:d /r /h %d in (*.*) do ( echo %cd & echo %d & call tidy.bat %d ) rem ----------------------------- rem Prepares manifest.txt files from 4NT DESCRIPT.ION files for the current directory tree rem by running mkmanifest.btm in each subdirectory. Goes only one level deep. rem pushd/popd allow us to put current directory back the way it was. for /h /a:d %d in (*.*) do ( pushd & cd %d & echo %cd & call mkmanifest.btm NOECHO & popd ) rem ----------------------------- rem Prepares manifest.txt files from 4NT DESCRIPT.ION files for the current directory tree rem by running mkmanifest.btm in each subdirectory. Covers all levels. rem pushd/popd allow us to put current directory back the way it was. for /h /r /a:d %d in (*.*) do ( pushd & cd %d & echo %cd & call mkmanifest.btm NOECHO & popd ) rem ----------------------------- rem conditional copy e: cd E:\com\mindprod rem scan the \com\mindprod tree for files of the form *.use. rem When you find one, only if there is also a version.txt in that directory rem copy that *.use file to uses.txt. rem this works because %cd matches the directory of the found *.use file. for /r /h %u in (*.use) do ( if exist %cd\version.txt copy %u %cd\uses.txt ) rem ----------------------------- rem run all the just.bat files in the current directory tree rem the [a] is a fake regex wildcard kludge. for /r %d in (just.b[a]t) do call just.bat rem ----------------------------- rem conditionally rebuild Jet exe from jar only if it out of date pushd C: CD E:\com\mindprod\converter if %@FILEAGE[converter.exe] GT %@FILEAGE[converter.jar] goto done call rejet.btm :done popd rem ----------------------------- rem strip off path and extension, and/or convert to an associated extension set f=%@NAME[%1] echo processing %f%.html rem ----------------------------- rem multiple commands one line. rem for each *.java file in the current directory, copy it to temp.txt, rem and run the blout utility on temp.txt. If the result temp.txt is a different rem length than the original file, replace the original file with it. for %i in (*.java) do ( copy "%i" temp.txt & C:\sys\blout.exe temp.txt & ^ if %@FILESIZE["%i"] != %@FILESIZE[temp.txt] copy temp.txt "%i" ) rem ----------------------------- rem multiple commands, multiple lines. rem nested ifs, recursively run proofs.bat in each "real" directory rem in the tree where there are some Java files rem note for uses /r for recursive where dir uses /s rem Beware. Do not tidy so () are on a line by themselves. for /a:d /r %d in (*.*) do ( if "%@right[4,%d]" != "^\raw" ( if "%@right[3,%d]" != "^\.." ( if "%@right[2,%d]" != "^\." ( if exist %d\*.java ( echo %d cd %d call C:\ENV\proofs.bat ))))) rem ----------------------------- rem detect if running under 4NT if "%@eval[2+2]" == "4" loadbtm on rem ----------------------------- rem display date, time timezone and cdrom drives available echo %_date %_time %_tzn %_cdroms rem displays: 2007-04-13 19:18:09 Pacific Daylight Time R: rem ----------------------------- rem control bat files with a string containing a letter coding rem for each step you want to execute. rem e.g. set whattodo=ACD rem Then before each step use code like this: if "%@index[%whattodo,A]" == "-1" goto bypassstepA ... if "%@index[%whattodo,B]" == "-1" goto bypassstepB ... if "%@index[%whattodo,C]" == "-1" goto bypassstepC ... if "%@index[%whattodo,D]" == "-1" goto bypassstepD ... rem in a real example you would use more mnemonic letter names. rem ----------------------------- rem convert Unicode 16LE *.htm files generated by PADGen to ordinary ASCII rem e.g. native2ascii.exe -encoding x-UTF-16LE-BOM myprog.htm myprog.html for %i in (*.htm) do native2ascii.exe -encoding x-UTF-16LE-BOM %i %@NAME[%i].html rem ----------------------------- rem change last modified/write date of the file, presuming DIR displays in YYYY-MM-DD format. rem /D must precede the filename. touch /Dw2007-01-31 temp.txt rem ----------------------------- ::The cdd command alone is worth the entire package. It lets you jump to ::any directory on any disk just by typing a few letters of its name, and if ::there are duplicates that fit the pattern, by selecting the one you want. ::It saves thousands of keystrokes every day. rem -30-