![](/img/trans.png)
[英]How to execute PowerShell script against all CSV files in a directory?
[英]How to Use Powershell to execute a program against all files in a directory
我正在使用Windows 8專業版,並希望做一些我希望非常簡單的事情。 我只想對目錄中某種類型的所有文件執行一個程序。 沒有樹,只是在平面目錄中。 在Linux中我會:
find . -name 'exec c:\user\local\bin\myprog {} \;
我真的花了幾個小時摔跤電源外殼,遇到政策問題,權限等等。有什么簡單的方法可以讓這種情況發生嗎?
這很簡單但與使用find
不同,例如:
Get-ChildItem -File | Foreach {c:\user\local\bin\myprog $_.fullname}
為了在命令行中執行操作,別名可以使這更簡潔:
ls -file | % {c:\user\local\bin\myprog $_.fullname}
PowerShell更喜歡焦點狹窄但可以在管道中組合在一起以提供大量功能的命令。 此外,PowerShell管道.NET對象,例如Get-ChildItem管道System.IO.FileInfo對象。 然后,您可以使用Foreach,Where,Select,Sort,Group,Format等命令來操作傳遞給管道的對象。 如果你有時間,我建議你查看我的免費電子書Effective PowerShell 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.