Blame Scripts/Bash/Functions/cli_getFilesList.sh

b7b189
#!/bin/bash
b7b189
#
b7b189
# cli_getFilesList.sh -- This function defines the list of FILES to
b7b189
# process.
b7b189
#
b7b189
# Copyright (C) 2009, 2010 Alain Reguera Delgado
b7b189
# 
b7b189
# This program is free software; you can redistribute it and/or
b7b189
# modify it under the terms of the GNU General Public License as
b7b189
# published by the Free Software Foundation; either version 2 of the
b7b189
# License, or (at your option) any later version.
b7b189
# 
b7b189
# This program is distributed in the hope that it will be useful, but
b7b189
# WITHOUT ANY WARRANTY; without even the implied warranty of
b7b189
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b7b189
# General Public License for more details.
b7b189
#
b7b189
# You should have received a copy of the GNU General Public License
b7b189
# along with this program; if not, write to the Free Software
b7b189
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
b7b189
# USA.
b7b189
# 
b7b189
# ----------------------------------------------------------------------
b7b189
# $Id$
b7b189
# ----------------------------------------------------------------------
b7b189
b7b189
function cli_getFilesList {
b7b189
8eeb3a
    local LOCATION=''
8eeb3a
8eeb3a
    # If first argument is provided to cli_getFilesList, use it as
8eeb3a
    # default location. Otherwise, if first argument is not provided,
8eeb3a
    # location takes the action value (ACTIONVAL) as default.
8eeb3a
    if [[ "$1" != '' ]];then
8eeb3a
        LOCATION="$1"
8eeb3a
    else
8eeb3a
        LOCATION="$ACTIONVAL"
8eeb3a
    fi
8eeb3a
8eeb3a
    # Re-define regular expression (REGEX) global variable to reduce
8eeb3a
    # the amount of characters we type in order to match find's
8eeb3a
    # output. When using regular expression with find, in order to
8eeb3a
    # reduce the amount files find, the regular expression is
8eeb3a
    # evaluated in the whole path. This way, when the regular
8eeb3a
    # expression is specified, we need to build it in a way that
8eeb3a
    # matches the whole path. Doing so each time we pass a `--filter'
8eeb3a
    # command-line argument may be a tedious task, so, in the sake of
8eeb3a
    # reducing some typing, we prepare the regular expression here to
8eeb3a
    # match the whole path using the regular expression provided by
8eeb3a
    # the user as pattern.
8eeb3a
    REGEX="^${LOCATION}/.*${REGEX}$"
8eeb3a
8eeb3a
    # Define list of files to process.
8eeb3a
    if [[ -d $LOCATION ]];then
8eeb3a
        FILES=$(find $LOCATION -regextype posix-egrep -type f -regex "${REGEX}")
8eeb3a
    elif [[ -f $LOCATION ]];then
8eeb3a
        FILES=$LOCATION
8eeb3a
    fi
8eeb3a
8eeb3a
    # Check list of files to process. If we have an empty list of
8eeb3a
    # files, inform about it and stop script execution.
8eeb3a
    if [[ $FILES == '' ]];then
8eeb3a
        cli_printMessage "`gettext "No file found."`" 'AsErrorLine'
8eeb3a
        cli_printMessage "$(caller)" 'AsToKnowMoreLine'
b7b189
    fi
b7b189
b7b189
}