Backing up all folders in a directory? Using 'for'

Started by megatron-uk, March 31, 2021, 09:14:57 PM

Previous topic - Next topic


I'm trying to write a couple of batch files to automate the backup all of the folders in a directory as individual archives, but I'm struggling to work out how to do this in Human68k.

In MS-DOS I would use something like:

for /d %%d in (A:\Games\*.*) do lha a -r %%d.lha %%d
... but the directory switch /d doesn't exist in Human68K, so you can only seem to pass file match parameters (*.txt, *.* etc).

Any ideas?



Unfortunately, that doesn't match anything - in DOS/Windows CMD prompt it would, but on Human68k it doesn't glob anything:




Ah damn, yeah Human68k is not a DOS port after all, only a dos-like imitation so it doesn't work quite the same way.


At the moment I'm trying to bolt something together using the Human68k ports of bash.x, cat.x and ls.x - I'm getting there, but slower than I'd like since the '|' operator doesn't seem to play nicely and variable substition in shell files using Bash 1.x on the X68000 doesn't work exactly the way I'm used to it working for the last ~25+ years....


Ok, got a working solution using:

- zip.x
- bash.x
- ls.x
- tr.x


echo "Generating list..."

ls.x -1 | tr.x -d '\015' > files.txt


echo "Starting to write batch file..."

while read D

 test -d "$D"
 if [ "$?"=="0" ]

 d=`echo $D`
 #echo "$d"
 echo -n "zip.x -b $OUTPUT -0 $OUTPUT\\$ $d\\*.*"  >> cmd.bat
 echo -e "\r" >> cmd.bat   

done < files.txt

echo "Now run cmd.bat"

Bash has some wacky limitations on this port - line spacing, pipes and such like; I had to play around with the whitespace in the script until it would work correctly. There are also some silly things like converting the CRLF output from ls.x to just LF (the 'tr -d' command does that).

Anyway, it generates a batch file with a unique line for each sub folder. You then call the batch file when its finished and it zips each in turn.

Improvements: pass in the source directory and the destination folder. For now I'm hard coding it to A:\Games and my E:\ shared drive in XM6G.