Das Betriebssystem ist Windows 10.
Ich verwende den PowerShell-Befehl „Get-FileHash“, um die MD5-Prüfsumme einer Datei direkt in ihrem Ordner zu generieren, und zwar wie folgt:
PS Z:\Test> Get-FileHash 'test.txt' -algorithm MD5
Algorithm Hash Path
--------- ---- ----
MD5 D41D8CD98F00B204E9800998ECF8427E Z:\Test\test.txt
Bei langen Dateipfaden scheint PowerShell die Datei jedoch nicht über Get-FileHash finden zu können.
PS Z:\Test loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong> Get-FileHash 'looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong.txt' -algorithm MD5 Resolve-Path : Cannot find path 'Z:\Test looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
oooooooooooooooooooooooooooooooooooooooong\looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
oooong.txt' because it does not exist.
At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Utility\Microsoft.PowerShell.Utility.psm1:11
0 char:36
+ $pathsToProcess += Resolve-Path $Path | Foreach-Objec ...
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Z:\Test loooooo...ooooooooong.txt:String) [Resolve-Path], ItemNotFoundE
xception
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.ResolvePathCommand
Andererseits ist es durchaus möglich, die Datei mit „Get-ChildItem“ zu finden:
PS Z:\Test loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong> Get-ChildItem
Directory: Z:\Test looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
oooooooooooooooooooooooooong
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2024-02-26 12:55 0 loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
ooooooooooong.txt
Wie generiere ich in solchen Fällen MD5:s? Ich habe keine Administratorrechte.
Antwort1
Sie können einen Pfad mit erweiterter Länge angeben, indem Sie \\?\
ihm etwas voranstellen und den -LiteralPath
Parameter verwenden, etwa:
# local path
Get-FileHash -LiteralPath '\\?\C:\long\path\to\file.txt'
# network share
Get-FileHash -LiteralPath '\\?\UNC\server\share\folder\file.txt'
Dadurch werden die meisten Programme davon überzeugt, lange Pfadnamen zu akzeptieren, und es sind keine Administratorrechte erforderlich.
Weitere Informationen finden Sie in der Antwort hier:https://stackoverflow.com/a/21194605/7411885