2011-11-14 90 views
3

我有一個文件夾中的許多文件用這種格式羣衆文件重命名 - PowerShell的

constant_blah_blah_blah.png 

我怎樣才能空格替換下劃線,並且還使用PowerShell從中取出constant_?

在此先感謝。

+0

很抱歉,但我還沒有嘗試過任何東西。我不知道PowerShell是如何工作的。 – Tsarl

+0

您應該嘗試在此處搜索,Google和/或查看MSDN上的Powershell文檔。 –

回答

6

你可以試試這個

Get-childItem constant* | % {rename-item $_.name ($_.name -replace '_',' ')} 
Get-childItem constant* | % {rename-item $_.name ($_.name -replace 'constant ','')} 
+0

雖然這將做兩個重命名,這是沒有必要的(請參閱我的答案)。 – Joey

5
# gather all files that match the criteria 
Get-ChildItem constant_* | 
    ForEach-Object { 
     # remove the "constant_" from the beginning and replace _ by space. 
     Rename-Item $_ ($_.Name -replace '^constant_' -replace '_', ' ') 
    } 

或更短:

ls constant_* | %{rni $_ ($_.Name -replace '^constant_' -replace '_', ' ')} 
+0

+1用於過濾和擴展ls /%。 –

相關問題