示例文件名为PO 2171 Cresco REVISED.pdf .这些文件很多,文件名不规范,空格位置不固定。中间空间是大于128的字符ASCII代码,我希望用"_“一次替换大于128的字符ASCII代码。
我还没学过Powershell。非常感谢。
发布于 2022-05-21 11:33:45
为此,您需要regex。
下面我使用ASCII范围32-129(在十六进制\x20-\x81中)来替换任何控制字符:
(Get-ChildItem -Path 'X:\TheFolderWhereTheFilesAre' -File) |
Where-Object { $_.Name -match '[^\x20-\x81]' } |
Rename-Item -NewName { $_.Name -replace '[^\x20-\x81]+', '_' }Regex详细信息:
[^\x20-\x81] Match a single character NOT in the range between ASCII character 0x20 (32 decimal) and ASCII character 0x81 (129 decimal)
+ Between one and unlimited times, as many times as possible, giving back as needed (greedy)https://stackoverflow.com/questions/72328896
复制相似问题