2 # copy or move Artistic Style backup files to a backup directory
4 # CHANGE THE FOLLOWING 4 VARIABLES
5 # $indir is the input top level directory containing the .orig files
6 # $outdir is the output top level directory containing the moved files
7 # $fileext is the backup file extension
8 # $copyfiles is COPY (cp) or MOVE (mv) the files
9 # spaces ARE allowed in directory and file name (for Cygwin on Windows)
11 indir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
12 outdir="astyle_backup"
15 # USE ONE OF THE FOLLOWING TO COPY OR MOVE THE FILES
19 # display the variables
21 echo "\"$copyfiles\" Artistic Style backup files"
26 # validate input directory
27 if [ ! -d "$indir" ] ; then
28 echo "Input directory does not exist!"
32 if [ "$indir" == "$outdir" ]; then
33 echo "Input and output directories are the same!"
38 # optional statement to run Artistic Style
39 # astyle -R "%indir%\*.cpp" "%indir%\*.h"
40 # if [ $? -ne 0 ] ; then read -sn1 -p "Error executing astyle!"; fi
42 # variables for fle processing
43 #echo "processing files..."
44 fileHasSpaces=false # a file or directory name has spaces
45 extLength=${#fileext} # length of the file extension
47 # loop thru the input directory to find the .orig files
48 # then move the .orig file to the new directory
49 for file in `find "$indir" -type f -name "*$fileext" ` ; do
51 # allow spaces in file names for Cygwiin on Windows
52 # test if this is a continuation line and build $infile
53 if [ $fileHasSpaces = true ] ; then
59 # test end of string for no file extension
60 if [ ! "${infile:(-$extLength)}" = $fileext ] ; then
68 # replace input file directory with output directory
69 # ${string/substring/replacement}
70 outfile=${infile/$indir/$outdir}
73 # strip filename from back of the output file
74 # ${string%substring} - /* strips from last '/' to end
78 # create output directory
79 [ ! -d "$outpath" ] && mkdir -p "$outpath"
81 # copy or move the files
82 $copyfiles -f "$infile" "$outpath"
83 if [ $? -ne 0 ] ; then
84 read -sn1 -p "press any key to continue!"
88 # echo for every 100 files processed
91 [ $mod -eq 0 ] && echo $count files processed
94 echo $count files processed