Post subject: Drag'n'drop hash report script
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11492
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
Verifying the hell out of http://tasvideos.org/EmulatorResources/PCem/DOS/Configurations.html almost drove me crazy with how many md5 hashes I had to check. Even more to come now that we accept llibTAS+PCem submissions. So I needed some incredibly quick way to know a hash of some file, or of all files in a folder. Drag'n'drop feels like the quickest way. Unfortunately, lubuntu doesn't let you drag'n'drop onto scripts, but you can make a script launch a terminal and repeatedly accept your drag'n'drops, printing stuff. So here's a script that you usually run on Linux, because it's a Shell script. But if you are on Windows and you associate this file with your mingw64.exe or whatever you're using, double-clicking on the script will launch you a nice md5-drag-n-drop terminal! Supports paths with spaces and nested folders. Props to mjbudd77 and F. Hauri. Download md5.sh
Language: shell

#!/bin/bash echo -ne "\033]0;Drag & drop file or folder\007" while IFS=$'\t\r\n' read -d '' -rsn 1 str && [ "$str" ]; do while IFS= read -d '' -rsn 1 -t .02 char; do str+="$char" done if [ "$str" ]; then find "$str" -type f -exec md5sum {} \; fi done
Suggest improvements!
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.
Editor, Player (69)
Joined: 6/22/2005
Posts: 1050
I've made a Windows batch script with similar functionality. It uses the CertUtil command-line program that is included with Windows (at least Win7 and later). The lines containing pause are necessary in order to prevent the window from closing if you're using drag-and-drop. Unfortunately, this means that you'll need to press a key to terminate the script if you run it from the command prompt and redirect the output (e.g., to a file). Download hash_dir.bat
Language: batch

@echo off setlocal enableextensions if [%1]==[] goto synerr if not exist %1 goto nofile call :isdir %~a1 if [%_is_dir%]==[F] call :procfile "%~f1" if [%_is_dir%]==[T] call :procdir "%~f1" goto:eof :synerr echo. echo Calculates MD5 hash for the input file(s) using Windows's CertUtil command. echo. echo USAGE: %~nx0 ^<input^> echo ^<input^> File or directory for which to generate hashes. If directory, echo processes all contained files and subdirectories. echo. goto:eof :nofile echo. echo ERROR: %1 does not exist. goto:eof :isdir set _is_dir= set _attr=%1 if [%_attr:~0,1%]==[d] ( set _is_dir=T ) else ( set _is_dir=F ) goto:eof :procfile set _hash= set _fname="%~f1" set _fname=%_fname:^^=^% for /f "delims=" %%A in ('CertUtil -hashfile %_fname% MD5 ^| find /i /v "md5" ^| find /i /v "certutil"') do set "_hash=%%A" echo %_hash: =% %_fname% if [%_is_dir%]==[F] pause goto:eof :procdir for /f "delims=" %%A in ('dir /a-d /b /s "%~f1"') do call :procfile "%%~fA" pause goto:eof
Current Projects: TAS: Wizards & Warriors III.
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11492
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
In my script I noticed that if you drop a file or a folder that has a space in its name, when running from mingw/msys2 it will say
find: ‘'/e/Users/feos/Desktop/thunderaxe31-gameboycamera_gambatte 2.bk2'’: No such file or directory
even tho the find command works if I supply it this path directly. Linux doesn't have this problem, nor does Dacicus's script (which prints =_fname is it's a link file).
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11492
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
Figured it out (thanks YoshiRulz for ideas) Download sha1sum.sh
Language: shell

#!/bin/bash echo -ne "\033]0;Drag & drop file or folder\007" prefix="'" suffix="' " while IFS=$'\t\r\n' read -d '' -rsn 1 str && [ "$str" ]; do while IFS= read -d '' -rsn 1 -t .02 char; do str+="$char" done if [ "$str" ]; then # in case your temrinal adds funny symbols on drag'n'drop #str="$(expr "$str" : "$prefix\(.*\)$suffix")" # or #str="$(printf "%s" "$str" | sed -e "s/^$prefix//" -e "s/$suffix//")" find "${str##*/}" -type f -exec sha1sum {} \; fi done
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.