REM Batch program for 4DOS to move and renumber files to a new subdirectory.
REM by John D. Cook June 2, 1993
REM Written to store new articles from Usenet news group comp.robotics
REM in sequentally numbered files. Only works with files that end in ".txt".
REM Cannot have a file not ending in a number, will cause nasty problems
REM since no number will be detected and files will get overwritten.
if exist %1.txt rename %1.txt %1.bad
if exist %2\%1.txt rename %2\%1.txt %2\%1.bad
REM First get the number of the highest numbered file in storage, this is max.
set namelen=%@len[%1]
pushd %2
for %a in (%1*.txt) if exist %@name[%a].txt (set a=%@name[%a] ^ set max=%@substr[%a,%namelen,3])
echo %max
REM Now set new to the next highest available number.
set new=%@eval[%max + 1]
popd
REM Last, move each new file to storage, updating the number so they are sequential.
for %a in (%1*.txt) if exist %@name[%a].txt (set a=%@name[%a] ^ set curr=%@substr[%a,%namelen,3] ^ move %1%curr.txt %2\%1%new.txt ^ set new=%@eval[%new + 1])