Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/bash
- directory_explore(){
- #moved to src dir
- local path_dir=$1
- echo $path_dir +++++++++++++++++++++++++++++
- echo before pwd jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
- pwd
- ## CHAMGED HERE ;;; NEED TO GO FROM ROOT DIR TO ACCUMULATED PATH
- #ACCUMULATED PATH = PATHDIR
- cd "$root_dir" # absolute path of root
- cd "$path_dir" # relative path from root to current
- echo after pwd jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
- pwd
- #cd "$1"
- echo INTO NEW DIRECTORY DONE
- for f in *
- do
- if [ -d "$f" ]; then # if this is a directory
- local new_path_dir="$path_dir/$f"
- # directory_explore $1/$f
- echo WILL BE ENTERING NEW PATH $new_path_dir
- directory_explore $new_path_dir
- elif [ -f "$f" ]; then #if this is a file
- # now check if th file matches our array
- local file_name=$(basename -- "$f")
- local extension="${file_name##*.}"
- #file_name="${filename%.*}"
- #extracted file name and extension
- pwd
- echo "file name $file_name"
- echo "extension $extension"
- bool=0
- for i in $arr
- do
- echo "$extension"
- echo "$i"
- if [ $extension = $i ]
- then
- echo ++++++++++++++++++++++++++++++
- bool=1
- break;
- fi
- done
- #if bool becomes 1, means this $f is a desired file, dont do anything
- #else make a directory named after $extension in the sub and move this $f there
- echo $bool
- echo 0000000000000000000000000000
- if [ $file_name = $extension ]; then
- mkdir -p $cp_dir/others
- cp $f $cp_dir/others
- echo "$file_name CREATED IN oTHER"
- #went to dir
- cd $cp_dir/others
- touch desc_others.txt
- echo "$path_dir/$file_name/" >> desc_others.txt #writing in file done
- #came back
- cd -
- echo "after writing logfile HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH"
- pwd
- elif [ $bool -eq 0 ]; then
- # echo $cp_dir
- mkdir -p $cp_dir/$extension
- cp $f $cp_dir/$extension/$file_name
- echo "$file_name CREATED"
- #went to dir
- cd $cp_dir/$extension #went to write logfile
- #local filenaam="desc_${file_name}.txt"
- #touch "desc_${file_name}.txt"
- touch log.txt
- echo "$path_dir/$file_name/" >> "log.txt" #writing in file done
- echo WRITE DONE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- cd - # came back
- fi
- fi
- done
- cd ..
- echo "EXITIG DIRECTORYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY DONEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE PWD"
- pwd
- }
- csv_file_write(){
- cd $root_dir
- cd ../output
- pwd
- touch A.csv
- echo "Filetype,No_of_files" >> A.csv
- count=-1
- for f in * #f is folder name
- do
- if [ -d "$f" ]; then #this is a folder
- cd ./$f
- count=-1
- for f1 in *
- do
- count=$((count+1));
- echo $count
- done
- cd ..
- echo "$f,$count" >> A.csv
- elif [ -f "$f" ]; then #if this is a file
- echo hahavodox
- fi
- done
- cd .. #exited from output folder
- mv ./output/A.csv $root_dir/A.csv
- }
- root_dir=$(pwd)
- # S1 S2
- # -----------------------make user give input
- if [ $# -eq 0 ];then
- echo "you have to input a filename"
- read filename
- until [ -f "$filename" ]
- do
- echo "wrong filename. input a valid one"
- read filename
- done
- else
- if [ $# -eq 1 ];then
- filename=$1
- else
- filename=$2
- dirr=$1
- fi
- fi
- # ---------------------------checking if file exists
- until [ -f "$filename" ]
- do
- echo "wrong filename. input a valid one"
- read filename
- done
- echo "you inputed this filename $filename"
- # ----------------------checking done, trying to read file and put it in arr ARRAY
- #readarray -t arr < $filename
- arr=$(<$filename)
- for i in $arr
- do
- echo $i
- done
- # ------------------------ stroing the destination directory
- cd ..
- mkdir -p output
- cd output
- cp_dir=$(pwd) #this is the path to copy a file
- cd $root_dir
- # ----------------------- steoing the src directory
- if [ $# -eq 1 ];then
- #explore_dir=$(pwd) # source is currnt working directory
- path=. # current directory is working directory
- else
- # cd $1 # source is given
- # explore_dir=$(pwd)
- # cd ..
- path=./$1
- fi
- echo $path
- directory_explore $path
- csv_file_write
- # echo $explore_dir
- # echo $cp_dir
- # cd $explore_dir
- # pwd
- # all directories are good and
- #I am in cexplore directory
- # directory_explore $explore_dir
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement