#!/bin/bash if [ $(echo "$0"|cut -c1) != "/" ] then # zenity --warning --title="半角スペース除去スクリプト" --text="このスクリプトは必ず、root(/)ディレクトリからのフルパスで実行してください。\n例)$ bash /home/kiyoshi/gtk_delSpaceInFileName.sh" # exit 0 script1="$PWD"/$0 script2="$PWD"/"$(echo "$0"|sed -e "s/[^\/]*$//")""gtk_delSpaceInFileNameDuplicated2.sh" else script1="$0" script2="$(echo "$0"|sed -e "s/[^\/]*$//")""gtk_delSpaceInFileNameDuplicated2.sh" fi if [ -z "$1" ] then zenity --info --title="半角スペース除去スクリプト" --text="次のウィンドウでは、含まれるファイルやディレクトリ(サブディレクトリおよびその中のファイルも含む)\nの名前の中に含まれる半角スペースを除去したいディレクトリを指定してください。" dir=$(zenity --title="半角スペース除去スクリプト" --file-selection --directory) if [ $? = 1 ] then zenity --title="半角スペース除去スクリプト" --text="キャンセルが押されたので終了します。" exit 0 fi if [ -z "$dir" ] then zenity --title="半角スペース除去スクリプト" --text="ディレクトリが選択されなかったので終了します。" exit 0 fi zenity --question --title="半角スペース除去スクリプト" --text="${dir}の中のファイルやディレクトリの名前の半角スペースを除去します。よろしいですか?" if [ $? = 1 ] then zenity --title="半角スペース除去スクリプト" --text="キャンセルが押されたので終了します。" exit 0 fi else dir="$1" echo $1 fi if [ ! -w "$dir" ] then zenity --warning --title="半角スペース除去スクリプト" --text="${dir}ディレクトリに書き込めませんので、この中のファイルの名前は変更できません。" & exit 0 fi cd "$dir" for a in * do if [ -d "$a" ] then if [ -x "$a" ] then bash "${script1}" "${dir}/$a" else zenity --warning --title="半角スペース除去スクリプト" --text="${dir}$aディレクトリ内を閲覧できませんので、この中のファイルの名前は変更できません。" & fi fi goalname="$(echo "$a"|tr -d " ")" if [ "${goalname}" != "$a" ] then if [ -e "${goalname}" ] then bash "${script2}" "${dir}/$a" else mv "$a" "${goalname}" fi fi done