idrassi / DirHash

Windows command line utility to compute hash of directories and files
BSD 3-Clause "New" or "Revised" License
111 stars 11 forks source link

Can't use DirHash if the path contains an apostrophe #30

Closed a84r7a3rga76fg closed 1 year ago

a84r7a3rga76fg commented 1 year ago

I'm using Powershell Core and nothing happens when I try to use DirHash on such a path with .

idrassi commented 1 year ago

Thank you for raising this issue. The behavior you're experiencing is not actually due to DirHash itself, but rather how PowerShell Core interprets paths that contain certain special characters like an apostrophe '.

In PowerShell, certain characters are reserved and have special meanings, and apostrophe is one of them. To ensure these characters are interpreted literally in a path (or any string), you should encapsulate the entire string in double quotes ".

Here's an example of how you should be running DirHash in PowerShell Core when the directory contains an apostrophe: DirHash "C:\Users\yourUser\yourFolder'sName"

And here is a demonstration showing that DirHash indeed works under PowerShell with a directory that contains an apostrophe when the path is enclosed within double quotes: image

If you don't use double quotes, PowerShell may not interpret the command correctly and would just wait for more input without actually invoking DirHash: image

Interestingly, this issue doesn't occur in the Windows command prompt, which doesn't require the path to be enclosed in quotes if it contains an apostrophe '.

I hope this clarifies the issue for you. Feel free to reach out if you have more questions or concerns.

a84r7a3rga76fg commented 1 year ago

It's a different single quotation mark in the path, the first works but not the second. U+0027 : ' U+2019 :

Nothing happens when the path is enclosed with double quotes.

dirhash "C:\Users\Abc\Desktop\123\The car's engine" Blake3 -t "C:\Users\Abc\Desktop\123\The car's engine\test.blake3" -progress -sum -sumRelativePath -nowait -nologo -quiet -overwrite -exclude *.txt -exclude *.blake3

But with single quotes, this happens.

dirhash 'C:\Users\Abc\Desktop\123\The car's engine' Blake3 -t 'C:\Users\Abc\Desktop\123\The car's engine\test.blake3' -progress -sum -sumRelativePath -nowait -nologo -quiet -overwrite -exclude *.txt -exclude *.blake3
Error: Argument "s" not recognized
idrassi commented 1 year ago

Thank you for your follow-up question and for providing additional context.

I understand the confusion now, you're dealing with a different special character (U+2019 : ). This character might indeed be causing the problem, but using double quotes should handle it correctly.

The fact that you're not seeing anything happening in the console is likely due to the -quiet switch in your command. This switch suppresses the output to the console, but it doesn't affect the output being written to the file specified by the -t switch.

I've tested your exact scenario with a path containing the special single quote (U+2019 : ), and the output was correctly written to the test.blake3 result file. You can see the successful execution in the following screenshot, where I used the more command to display its content: image

I suggest that you remove the -quiet switch and rerun your command. This way, you'll be able to see the execution progress and any potential error messages directly in the console.

a84r7a3rga76fg commented 1 year ago

Without -quiet, it says this.

!!!Failed to open the Blake3 SUM file for writing!!!
Error: The given input file doesn't exist

I can see it in the output from ls but can't enter it.

Set-Location: Cannot find path 'C:\Users\Abc\Desktop\123\The cars engine' because it does not exist.

Powershell can't paste so I have to enter it manually, then it says this.

Error: Argument "s" not recognized
idrassi commented 1 year ago

Thank you for your response. It seems like the issue is indeed about how the special character (U+2019 : ’) in the file path is being handled.

PowerShell has a feature known as tab completion, which can help you here. Instead of trying to type out the directory name manually, especially when it contains special characters, you can start typing the first few letters of the directory name and then press the Tab key. PowerShell will then attempt to auto-complete the directory name for you.

This is particularly useful when dealing with special characters because it will use the exact character present in the file path, thereby avoiding the confusion of similar looking, but technically different characters (like U+0027 and U+2019 in this case).

Please give this a try and let me know if it helps or if you're still experiencing issues.

a84r7a3rga76fg commented 1 year ago

That works. I also found out that right clicking on the Powershell window to paste something ignores special characters but ctrl+v doesn't. Thanks for the help.