Created
July 7, 2021 10:31
-
-
Save mu373/962c239b7ba37132f15901c75b3dd2e4 to your computer and use it in GitHub Desktop.
ファイルのハッシュ値を計算してリネームする
This file contains 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/zsh | |
set -e | |
IFS=$'\n' | |
filePath=$1 | |
fileDir=`dirname $filePath` | |
fileName=`basename $filePath` | |
fileExt=`echo $fileName | sed -r 's/(.*)(\.[^\.]*$)/\2/'` | |
# 拡張子を持たないファイルのための処理 | |
if [ $fileName == $fileExt ]; then | |
echo "no extension" | |
fileExt="" | |
fi | |
# ハッシュ値を計算 | |
hashOfFile=`sha3sum -a 512 $1 | cut -d " " -f 1` | |
newFileName=$hashOfFile$fileExt | |
newFilePath=$fileDir/$newFileName | |
mv $filePath $newFilePath | |
echo "Original file name: " $fileName | |
echo "New file name:" $newFileName | |
echo "Hash Algorithm: SHA3-512" | |
# ログは~/Library/Logs/hashRename.logに出力 | |
echo \""$filePath"\""\t"\""$newFilePath"\" >> ~/Library/Logs/hashRename.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment