Batch CRC-tool
Moderators: Hacker, petermad, Stefan2, white
-
- Junior Member
- Posts: 14
- Joined: 2012-12-02, 21:58 UTC
Batch CRC-tool
Hi. I have a little problem
I want to calculate CRC of different directory. Is there a way to use crc tools in a sequential mode?
Example:
Dir0001
Dir0002
Dir0003
......
I want to have
Dir0001.sfv
Dir0002.sfv
Dir0003.sfv
If I select all the 3 dirs I will have a only "parent dir name".sfv
If I use the CRC on the single dir is perfect but the performance are very low
I would like to use a batch to select the dirs and launch the crc tools in sequential way to obtain unattended process and the full speed
Any help will be appreciated
Thanks
I want to calculate CRC of different directory. Is there a way to use crc tools in a sequential mode?
Example:
Dir0001
Dir0002
Dir0003
......
I want to have
Dir0001.sfv
Dir0002.sfv
Dir0003.sfv
If I select all the 3 dirs I will have a only "parent dir name".sfv
If I use the CRC on the single dir is perfect but the performance are very low
I would like to use a batch to select the dirs and launch the crc tools in sequential way to obtain unattended process and the full speed
Any help will be appreciated
Thanks
You can't do that in TC afaik. Here's a PowerShell script you might find useful.
It will create individual .md5 files for all passed folders. It will only accept folders and it won't overwrite existing .md5 files.
Put it on a button with
Command:
Parameter:
There are three optional switches: -sha1, -insidefolder and -donttouch
-sha1 turns on the SHA1 algorithm instead of MD5 (CRC32/SFV is not available in the Get-FileHash function)
-insidefolder puts the checksum files inside the individual folders instead of their parent folder
-donttouch restores the last write time of the folders so it won't mess up the original date sorting (only used in combination with -insidefolder)
Activating them would look like this:
Parameter:
Save as "CreateChecksum.ps1" and adjust the path of the button parameter:
If you're running Win7 you need to install PowerShell v4.
*Edit:
Added "-insidefolder", "-sha1" and ExecutionPolicy
*Edit2:
Added "-donttouch"
*Edit3:
Bugfix
*Edit4:
Handle special characters
It will create individual .md5 files for all passed folders. It will only accept folders and it won't overwrite existing .md5 files.
Put it on a button with
Command:
Code: Select all
powershell.exe
Code: Select all
-NoExit -ExecutionPolicy remotesigned -Command "&{&'C:\PathTo\CreateChecksum.ps1' -listFile '%L'}"
-sha1 turns on the SHA1 algorithm instead of MD5 (CRC32/SFV is not available in the Get-FileHash function)
-insidefolder puts the checksum files inside the individual folders instead of their parent folder
-donttouch restores the last write time of the folders so it won't mess up the original date sorting (only used in combination with -insidefolder)
Activating them would look like this:
Parameter:
Code: Select all
-NoExit -ExecutionPolicy remotesigned -Command "&{&'C:\PathTo\CreateChecksum.ps1' -sha1 -insidefolder -donttouch -listFile '%L'}"
Code: Select all
# TC Button Parameter:
# powershell.exe
# -NoExit -ExecutionPolicy remotesigned -Command "&{&'C:\PathTo\CreateChecksum.ps1' -sha1 -insidefolder -donttouch -listFile '%L'}"
Param(
[Parameter(Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[string]$listFile,
[switch]$insidefolder,
[switch]$sha1,
[switch]$donttouch
)
if ($sha1)
{
$algo = "SHA1"
$extensionOutputFile = ".sha"
}
else
{
$algo = "MD5"
$extensionOutputFile = ".md5"
}
$contentListFile = Get-Content -Path $listFile
Write-Output ("Calculating $algo checksum for " + $contentListFile.Count.ToString() + " folders...")
$timeStart = Get-Date
foreach ($folder in $contentListFile)
{
$folderItem = Get-Item -LiteralPath $folder
$nameParentFolder = Split-Path -Path $folderItem -Parent
$isFolder = Test-Path -LiteralPath $folderItem -PathType Container
if ($isFolder)
{
if ($insidefolder)
{
$nameOutputFile = $folderItem.FullName + $folderItem.Name + $extensionOutputFile
$outputFolder = Get-Item -LiteralPath $folderItem.FullName
$lastWriteTimeOutputFolder = $outputFolder.LastWriteTime
}
else
{
$nameOutputFile = $nameParentFolder + '\' + $folderItem.Name + $extensionOutputFile
}
if (Test-Path -LiteralPath $nameOutputFile)
{
Write-Output ("`n" + $nameOutputFile + " already exists. Skipping")
}
else
{
$pathFolderItem = $folderItem.FullName.ToString().Replace('[','`[').Replace(']','`]')
$colFiles = Get-ChildItem -Path $pathFolderItem -Recurse -File
foreach ($file in $colFiles)
{
$hashFile = Get-FileHash -LiteralPath $file.FullName -Algorithm $algo
$relativeName = $file.FullName.Remove(0, $folderItem.FullName.Length)
if ($insidefolder)
{
$finalString = $hashFile.Hash + ' *' + $relativeName
}
else
{
$finalString = $hashFile.Hash + ' *' + $folderItem.Name + '\' + $relativeName
}
Out-File -LiteralPath $nameOutputFile -InputObject $finalString -Append
}
if ($donttouch -and $insidefolder)
{
$outputFolder.LastWriteTime = $lastWriteTimeOutputFolder
}
}
}
}
$timeEnd = Get-Date
$timeSpan = New-TimeSpan -Start $timeStart -End $timeEnd
Write-Output ("`nDone. Duration: " + $timeSpan.ToString("hh\:mm\:ss\,fff"))
*Edit:
Added "-insidefolder", "-sha1" and ExecutionPolicy
*Edit2:
Added "-donttouch"
*Edit3:
Bugfix
*Edit4:
Handle special characters
Last edited by ZoSTeR on 2015-03-09, 11:19 UTC, edited 18 times in total.
Just for info, if it's not working with an error 'cannot be loaded because running scripts is disabled on this system' start powershell as administrator and run this command 'Set-ExecutionPolicy RemoteSigned'.
And to ZoSTeR, if you can tell me what to modify inside the script to save md5 files INSIDE the folder it has scanned, this could be the most useful script ever, at least for me... so it looks like this:
Folder_1
--Folder_1.md5
Folder_2
--Folder_2.md5
Thank you.
And to ZoSTeR, if you can tell me what to modify inside the script to save md5 files INSIDE the folder it has scanned, this could be the most useful script ever, at least for me... so it looks like this:
Folder_1
--Folder_1.md5
Folder_2
--Folder_2.md5
Thank you.
-
- Junior Member
- Posts: 14
- Joined: 2012-12-02, 21:58 UTC
It doesn't work for me now... when I start it on two selected folders, I get this:
This is my version:
I am runing Windows 8.1 64 bit, and I don't know what is wrong
and the catch is, on other set of folders works like a charm. Both are with ASCII characters only, but one are created locally, and others are copied from linux samba share.
I can access them normally.
Code: Select all
Calculating SHA1 checksum for 2 folders...
Split-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\Program Files\totalcmd\CreateChecksum.ps1:33 char:42
+ $nameParentFolder = Split-Path -Path $folderItem -Parent
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Split-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SplitPathCo
mmand
Test-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\Program Files\totalcmd\CreateChecksum.ps1:34 char:33
+ $isFolder = Test-Path -Path $folderItem -PathType Container
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.TestPathCom
mand
Split-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\Program Files\totalcmd\CreateChecksum.ps1:33 char:42
+ $nameParentFolder = Split-Path -Path $folderItem -Parent
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Split-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SplitPathCo
mmand
Test-Path : Cannot bind argument to parameter 'Path' because it is null.
At C:\Program Files\totalcmd\CreateChecksum.ps1:34 char:33
+ $isFolder = Test-Path -Path $folderItem -PathType Container
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.TestPathCom
mand
Done. Duration: 00:00:00,134
Code: Select all
PS C:\Windows\System32\WindowsPowerShell> $PSVersionTable
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.34014
BuildVersion 6.3.9600.17090
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2

I can access them normally.
Hmm strange. You could try the following:
Replace line 32
with
This will write the folder strings to the console and -LiteralPath ignores any wildcard characters that might get in the way.
Replace line 32
Code: Select all
$folderItem = Get-Item -Path $folder"
Code: Select all
Write-Output $folder
$folderItem = Get-Item -LiteralPath $folder
Well, nothing happens. Just this:
At least no red letters.
Changed sha1 to md5, nothing.
Is it codepage problem? I've copy-pasted both lines in place of line 32, so I have now 1 line more.
Code: Select all
Calculating MD5 checksum for 21 folders...
(lists 21 folders in 1 second)
Done. Duration: 00:00:00,046
Changed sha1 to md5, nothing.
Is it codepage problem? I've copy-pasted both lines in place of line 32, so I have now 1 line more.
I've updated the code to handle problematic characters.
Tested with local drives and UNC paths:
@hlloyge:
If it still doesn't work please check if the folders/files have the "hidden" or "system" attribute. Also compare the file permission between the working and failing folders.
Tested with local drives and UNC paths:
Code: Select all
Folder with ' two ' single quotes\
Folder with [ open and ] closing bracket\
Folder with [ open bracket\
Folder with ] closing bracket\
Folder with `Backtick\
Folder with ' single quote\
Folder with $dollar and #hash\
Folder with .dot\
If it still doesn't work please check if the folders/files have the "hidden" or "system" attribute. Also compare the file permission between the working and failing folders.