zipping a directory when the file count is over $X

Hiya,

I've been plugging away at this script and I cant get it to behave as I need.

first off it fails to adhere to the conditions of the file limit, and zips the directory regardless of the file count and secondly, but less important it zips up the entire path not just the directory I'm after.

Been at this for hours and I could use a hand.

tired in glasgow

 
#!/bin/bash

location_Parent=/path/Parent
location_IMG=/path/IMG
location_AUD=/path/AUD
time_a=20090614-205534

echo zipping and deleting dupes
IMG_CNT_MAX=1000 
cd $location_IMG
 FILECOUNT=$(ls | wc -l)
        if [ $FILECOUNT < $IMG_CNT_MAX ]
        then
        echo "zipping and deleeting dupes";
        cd $location_Parent 
        tar -zcvf $time_a-IMG.tar.gz $location_IMG
        tar -zcvf $time_a-AUD.tar.gz $location_AUD
        
        wait 

        rm -r $location_IMG
        rm -r $location_AUD
            
            else
            echo "Number of files has not yet reached $IMG_CNT_MAX, not ready to archive";
        fi

You're using a string comparison operator in your test statement, replace this line:

if [ $FILECOUNT < $IMG_CNT_MAX ]

with:

if [ $FILECOUNT -lt $IMG_CNT_MAX ]

if [ $FILECOUNT < $IMG_CNT_MAX ]
then
echo "zipping and deleeting dupes";
cd $location_Parent
tar -zcvf $time_a-IMG.tar.gz $location_IMG
tar -zcvf $time_a-AUD.tar.gz $location_AUD

    wait 

    rm -r $location_IMG
    rm -r $location_AUD

this code actually zips all the path $location_IMG
and $location_AUD

try this

if [ $FILECOUNT -lt $IMG_CNT_MAX ]
then
echo "zipping and deleeting dupes";
cd /path/
tar -zcvf $time_a-IMG.tar.gz IMG*
tar -zcvf $time_a-AUD.tar.gz AUD*

    wait 

    rm -r IMG*
    rm -r AUD*

this should work