/* This script used to backup files whose names are * listed in a text file upon each drive. * * The format of the text file is that each filename * is contained upon a separate line (unquoted). The * drive is not included on the file/directory name. * If the name is a directory, and you wish to back * up all sub-directories inside of it as well, then * end the name with a backslash. * * Comment lines may be placed in the text file by * putting a semi-colon as the first character in * that line. * * We assume that the backup file is named 'backup.txt' * and is located in the root of the drive. * * For example, a typical backup file may look like this: ; This is my backup file for C drive ;Backup WINDOWS directory WINDOWS\*.* ;Backup WINDOWS\SYSTEM directory WINDOWS\SYSTEM\*.* ;Backup autoexec.bat autoexec.bat ;Backup config.sys config.sys */ again: /* Use Reginald's DRIVEMAP() built-in to get a list * of the fixed (hard) drives. */ listing = DRIVEMAP(, 'FIXED') /* Present the list of drives and let him choose which * to backup. */ SAY 'Which drive do you wish to backup?' i = 1 DO UNTIL listing == "" PARSE VAR listing drives.i listing SAY i '=' drives.i i = i + 1 END SAY i '= All drives' SAY i + 1 '= Quit' PULL answer /* Does he want to quit? */ IF DATATYPE(answer, 'W') == 0 | answer > i THEN RETURN /* Get which device to backup to. He should enter a * name that ends with a backslash, for example, * C:\My Backup Dir\ */ SAY 'Enter backup directory (ie, E:\) >' PULL destination /* Does he want to do all drives, or a particular drive? */ IF answer \= i THEN DO i = answer /* Loop once only */ answer = 1 END ELSE DO /* Loop for how many drives there are */ answer = answer - 1 i = answer END /* Do each drive */ DO answer /* Here's the name of our backup file */ filename = drives.i || 'backup.txt' /* Open our backup file */ IF STREAM(filename, 'C', 'OPEN READ') == 'READY:' THEN DO /* Trap any errors from LOADTEXT() */ SIGNAL ON NOTREADY NAME BadRead /* Read all of the lines of our backup file * into the stem variable mybackup. mybackup.0 * will indicate how many lines were loaded. * This text file contains a list of what files * to backup, one filename per line. */ CALL LOADTEXT('mybackup.', filename, 'TLB') /* Process all of the lines */ DO p = 1 TO mybackup.0 /* Is this line a comment? (ie, the first * character is a semi-colon. */ IF LEFT(mybackup.p, 1) \== ';' THEN DO /* It's not a comment, therefore, a filename * to backup. */ SAY 'Copying "' || drives.i || mybackup.p || '" to "' || destination || mybackup.p || '"' /* Make sure that backup directory exists */ error = DIR(destination || mybackup.p) IF error \== "" THEN SIGNAL CopyErr /* Is this a directory we're backing up, and we want all * sub-directories backed up inside of it too? If so, it * ends with a backslash. */ IF RIGHT(mybackup.p, 1) == '\' THEN error = CopyFolder(drives.i || mybackup.p, destination || mybackup.p, 1) ELSE /* Copy the file (or if name contains wildcards, all matching files) */ error = COPYFILE(drives.i || mybackup.p, destination || mybackup.p, 'R') IF error \== "" THEN DO CopyError: SAY error SIGNAL done END END /* test for a comment line */ END /* parsing all lines */ /* Now close the backup file */ CALL STREAM(filename, 'C', 'CLOSE') END /* opening backup text file */ /* An error opening the backup file */ ELSE SAY STREAM(filename, 'D') i = i - 1 END /* backup of each drive */ done: /* Alert user that backup is done */ CALL BEEP(1000, 500) /* See if he wants to backup another drive */ SIGNAL again BadRead: CALL CONDITION('M') CALL STREAM(filename, 'C', 'CLOSE') SIGNAL done /* Copies the contents of a folder and all sub-folders inside it */ CopyFolder: PROCEDURE /* Copy all files in this folder to destination folder */ error = COPYFILE(ARG(1), ARG(2), 'R') IF error \== "" THEN RETURN error /* DO UNTIL no more sub-folders */ DO UNTIL error \== "" /* Get the name of the next sub-folder inside of this folder */ error = MATCHNAME(ARG(3), 'name', ARG(1), 'D') /* No error? */ IF error == "" THEN DO /* Make sure that the sub-folder exists in the destination */ error = DIR(ARG(2) || '\' || name) IF error \== "" THEN DO BadCopyFolder: CALL MATCHNAME() RETURN error END /* Copy all files in this folder to destination folder */ error = CopyFolder(ARG(1) || '\' || name, ARG(2) || '\' || name, ARG(3) + 1) IF error \== "" THEN SIGNAL BadCopyFolder END END IF error == 'DONE' THEN error = "" /* Return an empty string if success, or an error message */ RETURN error