forked from npocmaka/batch.scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsha1.bat
More file actions
57 lines (51 loc) · 1.05 KB
/
Copy pathsha1.bat
File metadata and controls
57 lines (51 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@echo off
setlocal enableDelayedExpansion
if "%~1" equ "" (
echo no file passed
echo pass -help to see the help message
exit /b 1
)
for %%# in (-h -help /h /help) do (
if "%~1" equ "%%~#" (
echo generates SHA1 checksum for a given file
(echo()
echo USAGE:
(echo()
echo %~nx0 file [variable]
(echo()
echo variable string in which the generated checksum will be stored
(echo()
exit /b 0
)
)
if not exist "%~1" (
echo file %~1 does not exist
exit /b 2
)
if exist "%~1\" (
echo %~1 is a directory
exit /b 3
)
for %%# in (certutil.exe) do (
if not exist "%%~f$PATH:#" (
echo no certutil installed
echo for Windows XP professional and Windows 2003
echo you need Windows Server 2003 Administration Tools Pack
echo https://www.microsoft.com/en-us/download/details.aspx?id=3725
exit /b 4
)
)
set "SHA1="
for /f "skip=1 tokens=* delims=" %%# in ('certutil -hashfile "%~f1" SHA1') do (
if not defined SHA1 (
for %%Z in (%%#) do set "SHA1=!SHA1!%%Z"
)
)
if "%~2" neq "" (
endlocal && (
set "%~2=%SHA1%"
)
) else (
echo %SHA1%
)
endlocal