Created
November 30, 2023 19:57
-
-
Save adrianmgg/0dbd8830b2ffdc13dfb79d266a2e572d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# powershell one-liner to generate a regex that rejects filenames containing invalid characters | |
# NOTE: currently this only handles invalid *characters* - reserved names e.g. COM1 won't be matched by this. | |
# TODO would be good to handle that too though - either just hardcode it or try one of these | |
# https://stackoverflow.com/a/70794363/8762161 https://stackoverflow.com/a/54643724/8762161 | |
$valid_filename_pattern = [regex]::new(([System.IO.Path]::GetInvalidFileNameChars() | ForEach-Object {[regex]::Escape($_)} | Join-String -Separator '' -op '^[^' -os ']*$'), 'Compiled, CultureInvariant') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment