Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用powershell删除文件名开头的空格_Powershell - Fatal编程技术网

如何使用powershell删除文件名开头的空格

如何使用powershell删除文件名开头的空格,powershell,Powershell,我一直在使用下面的命令将当前目录位置下所有文件名和文件夹中的空格替换为下划线 dir -Force -Recurse | Rename-Item -NewName {$_.name -replace " ","_"} 如何指定仅替换文件名开头的空格(例如第一个字符) Get-ChildItem -Force -Recurse | Rename-Item -NewName ($_.Name -replace "^ ","_&

我一直在使用下面的命令将当前目录位置下所有文件名和文件夹中的空格替换为下划线

dir -Force -Recurse | Rename-Item -NewName {$_.name -replace " ","_"} 
如何指定仅替换文件名开头的空格(例如第一个字符)

Get-ChildItem -Force -Recurse | Rename-Item -NewName ($_.Name -replace "^ ","_")
你的帖子标题与你的要求不太一致

示例代码中还有一个语法错误(在尝试访问PSItem
$\uu
Name
属性时缺少句点)


尽管如此,我还是希望这就是你要找的。你大部分时间都在那里。
-replace
的第一个参数解释正则表达式。

是的,我的措辞很糟糕。我想更改当前路径下以空格开头的所有文件和文件夹,以删除空格并用下划线替换。我正在尝试你的代码。因此“^”表示文件或文件夹名的第一个字符?@katama777
-replace
使用正则表达式匹配<代码>^匹配字符串的开头。它不使用任何字符。