Last active
August 29, 2015 14:02
-
-
Save Cronus23/0f9602d590867acab913 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author: Napoleon Martin | |
# fileinpector.sh | |
# Desciption: The script searches a directory for files, looks up their filetype in the | |
# filetable.txt and rename the files using the correct extension using | |
# pattern matching. It must be able to work more than once without appending | |
# pattern duplicate extensions eg. file.txt.txt is not acceptable. | |
# Makes sure that fileinspector.sh can handle a single file or directory. | |
set -x | |
# Search in a file or directory for | |
#read -p "Enter a file or directory: " var1 | |
#echo $var1 | |
file=$1 | |
if [ -e $file ];then | |
# file --mime-type -b $file | |
for file in $file | |
do | |
if [ -d "$file" ] | |
then | |
echo " $file is a directory" | |
elif [ -f "$file" ] | |
echo "$file is a file" | |
#fi | |
printf "file does not exist" | |
var1=$(file --mime-type -b) | |
ls $file | |
grep var1 | |
#echo $file | sort | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
text/plain%%%txt | |
image/jpeg%%%jpeg | |
application/zip%%%zip | |
audio/mpeg%%%mpeg | |
text/x-shellscript%%%sh | |
video/mp4%%%mp4 | |
video/x-flv%%%flv | |
image/gif%%%gif | |
audio/x-wav%%%wav | |
application/x-empty | |
application/x-gzip%%%gz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#This is lab6 by Napoleon M | |
# calls tablemaker.sh | |
# | |
#test extension | |
testX(){ | |
if [ ! $( grep $1 filetable.txt) ] | |
then | |
echo $1 >> filetable.txt | |
lab5=$(which tablemaker.sh) | |
lab5 | |
fi | |
} | |
addext(){ | |
ntype=$(grep $1 filetable.txt) | |
ext=${ntype##*%} | |
if [ "$ext" ] && [ ! "${i#*.}" = $ext ]; then | |
echo mv "$i" "$i.$ext" | |
fi | |
} | |
isDir(){ | |
if [ -d $1 ] | |
then | |
echo "directory" | |
fi | |
Arg1=$1 | |
for i in $(ls $Arg1) | |
do | |
Type=$(file --mime-type -b $i) | |
testX $Type | |
addext $Type | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got some stuff up. check it out and comment please.