Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to copy for filename containing square brackets '[ ]' #12

Open
cho-uc opened this issue Oct 27, 2024 · 3 comments
Open

Fail to copy for filename containing square brackets '[ ]' #12

cho-uc opened this issue Oct 27, 2024 · 3 comments
Assignees

Comments

@cho-uc
Copy link

cho-uc commented Oct 27, 2024

Copying files with filename containing squarebracket "[ ]" will fail

Example:

  • Myfilename[123].txt -> fail, file is corrupted, but no error message
  • Myfailname].txt -> success
  • Myfailname[.txt -> fail with attached error message

Windows version : Windows 10 Version 22H2
PSVersion : 5.1.19041.5007

Command:
Copy-FileHash -Path .\Source\ -Destination .\Destination\ -Recurse -PassThru -Verbose

Error
@markwragg
Copy link
Owner

markwragg commented Oct 27, 2024

This is because the -Path parameter interprets square brackets as special characters. Other PowerShell cmdlets that handle paths do the same.

To have the square brackets treated literally, use the -LiteralPath parameter instead of -Path.

@cho-uc
Copy link
Author

cho-uc commented Oct 27, 2024

Hello,

Thank you for the quick reply.
I replaced the command with -LiteralPath but the issue persisted.
Copy-FileHash -LiteralPath .\Source\ -Destination .\Destination\ -Recurse -PassThru -Verbose

The file Myfilename[123].txt is inside Source folder.
Is the command above correct?

@markwragg
Copy link
Owner

I see the problem. The -LiteralPath parameter only applies to the source path, it doesn't use LiteralPath when retrieving the files in the source folder (or on the destination at all as it happens).

I can fix this, but it will need a code change.

@markwragg markwragg self-assigned this Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants