| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | E_WRONG_DIRECTORY=85 |
| 4 | |
| 5 | clearscip-shell system . . clear. # Clear the screen. |
| 6 | |
| 7 | TargetDirectory=/home/bozo/projects/GreatAmericanNovelscip-shell filesystem . . `/home/bozo/projects/GreatAmericanNovel`. |
| 8 | |
| 9 | cd $TargetDirectory |
| 10 | echoscip-shell system . . echo. "Deleting stale files in $TargetDirectory." |
| 11 | |
| 12 | if [scip-shell system . . `[`. "$PWD" != "$TargetDirectory" ] |
| 13 | then # Keep from wiping out wrong directory by accident. |
| 14 | echoscip-shell system . . echo. "Wrong directory!" |
| 15 | echoscip-shell system . . echo. "In $PWD, rather than $TargetDirectory!" |
| 16 | echoscip-shell system . . echo. "Bailing out!" |
| 17 | exit $E_WRONG_DIRECTORY |
| 18 | fi |
| 19 | |
| 20 | rmscip-shell system . . rm. -rf * |
| 21 | rmscip-shell system . . rm. .[A-Za-z0-9]* # Delete dotfiles. |
| 22 | # rm -f .[^.]* ..?* to remove filenames beginning with multiple dots. |
| 23 | # (shopt -s dotglob; rm -f *) will also work. |
| 24 | # Thanks, S.C. for pointing this out. |
| 25 | |
| 26 | # A filename (`basename`) may contain all characters in the 0 - 255 range, |
| 27 | #+ except "/". |
| 28 | # Deleting files beginning with weird characters, such as - |
| 29 | #+ is left as an exercise. (Hint: rm ./-weirdname or rm -- -weirdname) |
| 30 | result=$? # Result of delete operations. If successful = 0. |
| 31 | |
| 32 | echoscip-shell system . . echo. |
| 33 | lsscip-shell system . . ls. -al # Any files left? |
| 34 | echoscip-shell system . . echo. "Done." |
| 35 | echoscip-shell system . . echo. "Old files deleted in $TargetDirectory." |
| 36 | echoscip-shell system . . echo. |
| 37 | |
| 38 | # Various other operations here, as necessary. |
| 39 | |
| 40 | exit $result |