I need to write a shell script that traverses a given directory structure in multiple levels, recognizes the video files scattered in the folders and copies all of them to another single folder. The video files are really Macromedia Flash data files (saved in my browser's cache) and they do not have any particular extension like .MP4 or .FLV just aplhanumeric names.
Now, I managed to make a start:
#!/bin/bash
#This script checks if the given folder contains video file and copies them another folder
filePath=$1 #the argument(The folder Path)
if [[ -z "$filePath" ]]; then #empty argument check
echo "Please input the folder to search"
exit 1
fi
if [ -d "$filePath" ]; then
if [ -L "$filePath" ]; then #check if the input folder is a valid folder
echo "directory $file does not exist"
exit 1
fi
else #improper input given by the user
echo "$filePath is either not a valid directory or it is a file.Please enter a valid directory address"
exit 1
fi
find $filePath type -d | \ #the find here list all the files and directories in the given folder
while read i
do
if [[ -d "$i" ]]; then
idDirectory #Call the function
elif [[ -f "$i" ]]; then
#check if its the file in the expected format
#do the copy work
fi
done
exit 0
idDirectory(){ # A recursive function to go multiple levels of the directory tree
#the function which tells if the path is directory or file
#If its a directory then it will call itself, till it gets a file
#need some help here!!!!!
}
I need to write the recursive function that identifies and traverses directories.I tried this.
but it was not successful.