Method to auto generate .md5 after any file finished download?

Page 1 of 2 12 LastLast

  1. Posts : 20
    Win 10 Pro x64 21H1
       #1

    Method to auto generate .md5 after any file finished download?


    Hello users.
    Is there some method to automatically generate .md5 for file that just finished downloading? Either through some normal windows method/task scheduler/.bat file/script/etc.... ?
    Some 3rd party programs are ok too as long as they are doing only this thing and not much else.

    Thing is i usually launch multiple downloads over night and it is kind of painful to manually select all of them at once from different folders and subfolders.

    I am using QuickSFV to make manually .md5 for files after download but i thought there could be way to automate that.

    Tried wget but sadly couldnt get it working.

    Would be perfect if method works for all type of downloads for example standard browsers/FTP-transfering through phone/downloading softwares.

    Have anyone some experience with this?
    Of course im talking about windows - 10 x64
      My Computer


  2. Posts : 2,191
    Windows 10 Pro 64-bit v22H2
       #2

    Windows has a command line utility to do that:

    certutil -hashfile <file> MD5

    It is pretty fast. It generated an MD5 for a 3GB file on my computer in only 5 seconds.

    Hint: To make it easy for multiple files create the commands ahead of time in notepad. Then just paste the commands one at a time into the command line.

    For example, I create the following in Notepad and pasted it into the command line and pressed Enter.

    certutil -hashfile Windows-7-Home-Premium-64bit-SP1.X17-58997.iso MD5

    Method to auto generate .md5 after any file finished download?-checksum.jpg

    How to Check an MD5 Checksum on desktop/laptop (PC/MAC)
    Nutanix Support & Insights

    You can do multiple files using PowerShell:

    Get-FileHash -Algorithm MD5 -Path (Get-ChildItem "\\path\to\files\*.*" -Recurse)

    Example:

    Get-FileHash -Algorithm MD5 -Path (Get-ChildItem "*.*" -Recurse)

    Method to auto generate .md5 after any file finished download?-md5_powershell.jpg

    How to generate MD5 hash value for multiple files in a folder using cmd
    windows 7 - How to generate MD5 hash value for multiple files in a folder using cmd - Super User
      My Computers


  3. Posts : 779
    Windows 7
       #3

    This batch script will search a set of folders (provided as command-line arguments), and look for new files created in the past 24 hours. Both full and relative path names are supported.

    e.g. MD5.bat C:\folder1 D:\folder2 D:\long\path\somewhere\folder4

    MD5.bat
    Code:
    <# :
    @echo off
    setlocal
    set args=%*
    powershell -NoProfile Invoke-Expression ([System.IO.File]::ReadAllText('%~f0'))
    endlocal
    goto :eof
    #>
    
    $DaysPast = 1
    $Now = Get-Date
    
    if ($env:args -eq $null) {
        Exit
    }
    
    $Folders = @()
    $FolderName = $null; $token = $false
    
    foreach ($char in $env:args.ToCharArray()) {
        switch ($char)
        {
            '"' {
                if (-not $token) {
                    $token = $true
                }
                else {
                    $Folders += $FolderName
                    $FolderName = $null
                    $token = $false
                }
            }
            ' ' {
                if ($token) {
                    $FolderName += ' '
                }
                else {
                    $Folders += $FolderName
                    $FolderName = $null
                }
            }
            default {
                $FolderName += $char
            }
        }
    }
    
    if ($FolderName -ne $null) {
        $Folders += $FolderName
    }
    
    @(foreach ($Folder in $Folders -ne $null) {
        $NewerFiles = (Get-ChildItem $Folder -File -Recurse | where { $_.LastWriteTime -gt $Now.AddDays(-$DaysPast) }).FullName
    
        if ($NewerFiles -ne $null) {
            foreach ($File in $NewerFiles) {
                [PSCustomObject]@{
                    Time = (Get-Item $File).LastWriteTime
                    Filename = $File
                    MD5 = (Get-FileHash $File -Algorithm MD5 -ErrorAction SilentlyContinue).Hash
                }
            }
        }
    }) | Format-Table
    Code:
    C:\Users\GARLIN\Downloads\MD5>MD5.bat .
    
    Time                 Filename                                          MD5
    ----                 --------                                          ---
    7/9/2023 8:28:44 PM  C:\Users\GARLIN\Downloads\MD5\MD5.bat             67CC4A133572E6518C4BD80AA493300F
    7/9/2023 3:13:01 PM  C:\Users\GARLIN\Downloads\MD5\Untitled3.ps1       A93246D0F1211750D348D0A56BD99876
    7/9/2023 12:54:16 PM C:\Users\GARLIN\Downloads\MD5\W10_11StoreApps.bat B4E1962DAD2AFDE5AE5484FD99AD5B12
    7/9/2023 12:54:16 PM C:\Users\GARLIN\Downloads\MD5\W10_11StoreApps.ps1 64C1936AA80C98375BF6E775FF07454A
      My Computer


  4. Posts : 20
    Win 10 Pro x64 21H1
    Thread Starter
       #4

    Thanks for answers. Garlin method seems it is almost the thing i need. But i cannot get it to work. I guess i need to put my folder locations either in

    $Folders = @()
    or
    if ($token) {
    $FolderName += ' '
    Right? i put them there in ' ' and "" () but dunno what is wrong. Launching .bat just shows empty cmd for a couple seconds and i cant see anywhere .md5 created.
      My Computer


  5. Posts : 43,010
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #5

    Right?
    Wrong.

    Did you put the folder paths as arguments when you typed the command?

    MD5.bat C:\folder1 D:\folder2 D:\long\path\somewhere\folder4

    I.e. you must tell the bat file which folders to process.

    Hint: it would really help if opened a command window, then posted a screenshot of the command you typed and the result.
      My Computers


  6. Posts : 20
    Win 10 Pro x64 21H1
    Thread Starter
       #6

    Excuse me for beign dumb. What exaclty should i do?
    For example i have these folders where download are beign saved:
    "D:\DOWNLOADS\BROWSER"
    "D:\DOWNLOADS\SOFTDOWNS"
      My Computer


  7. Posts : 779
    Windows 7
       #7

    MD5.bat D:\DOWNLOADS\BROWSER D:\DOWNLOADS\SOFTDOWNS

    The script's expects to see arguments on the command-line. If you wanted to search the same folders every time, then change this part:
    $Folders = @("D:\DOWNLOADS\BROWSER", "D:\DOWNLOADS\SOFTDOWNS")
    $FolderName = $null; $token = $false

    foreach ($char in $env:args.ToCharArray()) {
    switch ($char)
    {
    '"' {
    if (-not $token) {
    $token = $true
    }
    else {
    $Folders += $FolderName
    $FolderName = $null
    $token = $false
    }
    }
    ' ' {
    if ($token) {
    $FolderName += ' '
    }
    else {
    $Folders += $FolderName
    $FolderName = $null
    }
    }
    default {
    $FolderName += $char
    }
    }
    }

    if ($FolderName -ne $null) {
    $Folders += $FolderName
    }
      My Computer


  8. Posts : 43,010
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #8

    I.e. if you want to search E:\Downloads

    you type the command

    MD5.bat E:\Downloads
      My Computers


  9. Posts : 20
    Win 10 Pro x64 21H1
    Thread Starter
       #9

    Ok i got it working. I am now closer what i wanted to achieve.
    Two things i forgot to mention (sry )

    1. But it still requires manually launching command after i check if all downs stopped. So for example if i leave pc to be running for week and downloading things then i will still need to launch .bat after everything finishes download so if i started downloading things on day 1 then everything stopped on day 7 then script will create md5 results only for files that were saved on day 7. Am i right?
    I belive to achieve that now i need some loop for this?

    2. I want to output results to .md5 file and save it in location of downloads with name of file like the file i downloaded - example:
    myvideo.mp4 --> myvideo.md5
    (ex: after downloading myvideo.mp4 from browser when finishes and is saved in D:\DOWNLOADS\BROWSER then script will output md5 results to myvideo.md5 file in the same location)
    I don't want it to be shown in cmd since if cmd/windows hangs-crashes results will be lost.
    On top of that will script created to do this not throw error like "filename.md5 exists" if script would run in loop?

    Ty
    Last edited by Milky Window; 10 Jul 2023 at 10:52.
      My Computer


  10. Posts : 779
    Windows 7
       #10

    Change $DaysPast from 1 to whatever value works for you. The idea is not to rescan the same files if you run the script on a normal schedule. While the script really doesn't care how many days back to count, I have no idea how many files (or how large your downloads are) and whether it takes a longer time to finish MD5 calculations.

    The point of the script is you asked to scan multiple folders for downloaded files. If you need to generate just one file, then use any one of many command-line MD5 or SFV tools out there.

    If you're expecting to have a Windows command magically launch after any random file gets written (via download tool or browser save) -- it doesn't work this way. The only way to implement this is a kernel filter driver which behaves like an anti-virus tool and scans every new file. No one's gonna write that for you.

    MD5v2.bat
    Code:
    <# :
    @echo off
    powershell -NoProfile Invoke-Expression ([System.IO.File]::ReadAllText('%~f0'))
    goto :eof
    #>
    
    $DaysPast = 1
    $Now = Get-Date
    
    $Folders = @("D:\DOWNLOADS\BROWSER", "D:\DOWNLOADS\SOFTDOWNS")
    
    foreach ($Folder in $Folders -ne $null) {
        $NewerFiles = (Get-ChildItem $Folder -File -Recurse | where { $_.LastWriteTime -gt $Now.AddDays(-$DaysPast) }).FullName
    
        if ($NewerFiles -ne $null) {
            foreach ($File in $NewerFiles) {
                $MD5 = (Get-FileHash $File -Algorithm MD5 -ErrorAction SilentlyContinue).Hash
                if ($MD5 -ne $null) {
                    "$File $MD5"
                }
            }
        }
    }
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 22:03.
Find Us




Windows 10 Forums