filenames - Refining a Folder Creation and move based on File Names Bash Script [SOLVED] -


i appologize in advance have looked , tried many of solutions problem out there none of them have worked perfectly. writing script create folder based on name of file move files of same name it. code have works errors. keeps throwing error folder exists after first pass. have tried if else doesn't seem handling right. if 1 me , tell me i'm doing wrong appreciate it. first part of script remove white space , replace _, works perfectly.

#!/bin/bash # main_dir=/pghwh1/photos cd $main_dir find . -name '* *' | while read fname      new_fname=`echo $fname | tr " " "_"`      if [ -e $new_fname ]             echo "file $new_fname exists. not replacing $fname"     else         echo "creating new file $new_fname replace $fname"         mv "$fname" $new_fname     fi done find . -type f | while read file;     f=$(basename "$file")     f1=${f%.*}     if [ -d "$f1" ];             mv "$f" "$f1"     else             mkdir "$f1"         chmod 777 "$f1"         mv "$f" "$f1"     fi done  


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -