#!/bin/sh ## ## SCRIPT NAME: findAniGIFfiles_forCriteria.sh ## ##+####### ## PURPOSE: ## This script finds a set of user-specified animated-GIF files --- according ## to a fully-qualified file mask (directory and mask) and about seven other ## 'find' parameters passed to this script. ## ## This shell script is meant to be issued from the Tk GUI 'wrapper' script ## 'find_and_aniGifViewers_FrontEnd.tk'. ## That Tk script is to get parameters for the 'find' command ## ##+###### ## INPUTS: ## ## The parameters passed to this script, from the ## 'find_and_aniGifViewers_FrontEnd.tk' Tk GUI script, are: ## ## Var1: 'Base'-directory name and file mask. Example: ## /home/fred/AniGIFs/*elephant*.gif ## ## Var2: A 'levels' indicator - from a Tk radiobuttons var. ## (possible values: 'one' or 'all'). ## ## Var3: A 'case-sensitivity' indicator - from a Tk radiobuttons var. ## (possible values: 'case-sensitive' or 'case-INsensitive') ## ## Var4: A 'bigger/smaller' indicator from a Tk radiobuttons var ##. (possible values: 'bigger' or 'smaller') ## ## Var5: An integer file-size-cutoff value (in KiloBytes) ## (could be null, indicating no size limitation) ## ## Var6: An 'older/younger' indicator - from a Tk radiobuttons var. ##. (possible values: 'older' or 'younger') ## ## Var7: An integer file-age-cutoff value (in days) ## (could be null, indicating no age limitation) ## ## Var8: A file-type string --- typically 'GIF' ## ## Var9: The name of a (temporary) output file to be used to ## hold the filenames found by the 'find' command. ## ## In this script, we will put those parameters in shell script variables ## VARfilemask, VARlevels, VARsense, ## VARbigsmall, VARfilesize, ## VARoldyoung, VARfileage, ## VARfiletype, VARoutfile --- respectively. ## ##+######################################################################### ## MAINTENANCE HISTORY: ## Started by: Blaise Montandon 2014may01 Made this 'findAniGIFfiles_forCriteria.sh' ## shell script by revising shell script ## 'findMediaFiles_forCriteria.sh' that ## was used for a script named ## ## Updated by: Blaise Montandon 2014may20 Put call to 'file-identify_aniGIF.sh' ## in the first part of the final 'if' ## statement in addition to the 2nd part. ##+######################################################################### ## FOR TESTING: (to show statements as they execute) # set -x VARfilemask="$1" VARlevels="$2" VARsense="$3" VARbigsmall="$4" VARfilesize="$5" VARoldyoung="$6" VARfileage="$7" VARfiletype="$8" VARoutfile="$9" ## FOR TESTING of this script without the Tk wrapper: ## (For stand-alone testing, change 'if test 1 = 0' to 'if test 1 = 1'.) if test 1 = 0 then # VARfilemask="$HOME/TESTfilesMOVIES/Images/anigif/*.gif" VARfilemask="$HOME/TESTfilesMOVIES/Images/anigif/*" VARlevels="one" # VARlevels="all" VARsense="case-sensitive" # VARsense="case-INsensitive" VARbigsmall="bigger" # VARbigsmall="smaller" VARfilesize="" VARoldyoung="older" # VARoldyoung="younger" VARfileage="" VARfiletype="GIF" # VARfiletype="" VARoutfile="/tmp/${USER}_tkBatchAniGifViewer_filenames.lis" fi ## FOR TESTING: # echo "VARfilemask: $VARfilemask" ## Simply exit if there is no filemask passed to this script. if test "$VARfilemask" = "" then exit fi DIRNAME=`dirname "$VARfilemask"` FILEMASK=`basename "$VARfilemask"` if test "$VARlevels" = "one" then DEPTHPARM="-maxdepth 1" else DEPTHPARM="" fi if test "$VARsense" = "case-sensitive" then NAMEPARM="-name" else NAMEPARM="-iname" fi ## The FILESIZE_PARM can be a parameter like ## -size +${SIZE_MINinBYTES}c ## for the 'find' command. if test "$VARfilesize" = "" then FILESIZE_PARM="" else SIZEinBYTES=`expr $VARfilesize \* 1000` if test "$VARbigsmall" = "bigger" then # FILESIZE_PARM="-size +${SIZEinBYTES}c" FILESIZE_PARM="( -size +${SIZEinBYTES}c -o -size ${SIZEinBYTES}c )" ## Note that we do not need to 'escape' the parentheses like we ## do in a 'find' command entered at a shell command prompt, because ## the parentheses are 'protected' by being within a variable, ## rather than being 'exposed' in a command string. else FILESIZE_PARM="-size -${SIZEinBYTES}c" fi fi ## The FILEAGE_PARM can be a parameter like ## -mtime +$NDAYS ## for the 'find' command. if test "$VARfileage" = "" then FILEAGE_PARM="" else if test "$VARoldyoung" = "older" then FILEAGE_PARM="-mtime +$VARfileage" else FILEAGE_PARM="-mtime -$VARfileage" fi fi ##+########################################################## ## Prepare to use the temp filename to hold the filenames. ## Make sure we start with a new (empty) output file. ##+########################################################## rm -f "$VARoutfile" ##+########################################################## ## Get the directory name of this script, to call ## on another script in the same directory as this script. ##+########################################################## thisDIR=`dirname $0` ##+##################################################### ## Call on the 'find' command, which puts the ## 'found' filenames, SORTED, in file "$VARoutfile". ## ## We use a '-type d -fprint /dev/stderr' clause in the ## 'find' command to show directories being searched, ## in the 'xterm' that runs this script. ## This gives a kind of 'progress indicator' to let the ## user know how far/fast the 'find' command is progressing. ## ## We also use the 'tee' command to output 'found' filenames ## to 'stdout', as a means of providing a 'progress ## indicator' in the 'xterm' that runs this script. ## However, if not many filenames are found and then the ## 'xterm' closes quickly, the user may not get much ## of a progress indicator by this. ## ## The directory-name output is probably going to be ## the better progress indicator in most cases. ##+#################################################### ## NOTE: Do not escape the quotes around $FILEMASK. ## If you do, no filenames are returned. ##+###################################################### ## FOR TESTING: (to show the 'find' commands as they execute) ## (When called from within the Tk wrapper script, ## this output may interfere with proper processing.) # set -x if test "$VARfiletype" = "" then find "$DIRNAME" $DEPTHPARM \ \( -type d -fprint /dev/stderr \) , \ \( -type f $NAMEPARM "$FILEMASK" \ $FILESIZE_PARM $FILEAGE_PARM -exec \ $thisDIR/file-identify_aniGIF.sh "GIF" {} \; \) | \ sort | tee "$VARoutfile" else find "$DIRNAME" $DEPTHPARM \ \( -type d -fprint /dev/stderr \) , \ \( -type f $NAMEPARM "$FILEMASK" \ $FILESIZE_PARM $FILEAGE_PARM -exec \ $thisDIR/file-identify_aniGIF.sh "$VARfiletype" {} \; \) | \ sort | tee "$VARoutfile" fi