如果我有一個exe檔想要透過PowerShell來搜尋檔名去跑
-
2010年6月17日 上午 07:06例如
要對 c:\work\code\1\ 下包含子目錄在內裡的所有 *.txt
透過 tool.exe 去輸出到 c:\work\code\2\
去跑像是
tool.exe c:\work\code\1\test1.txt c:\work\code\2\test1.txt /O3
這樣的方式
請問 PowerShell 的Script 該怎麼寫?
player
所有回覆
-
2010年6月17日 上午 07:26請參考之前類似的問題:http://social.technet.microsoft.com/Forums/zh-TW/powershellzhcht/thread/e5fee4b6-6125-483b-901c-631a92ef0b00
☞ 這裡是「免費的討論區」,付費支援服務請造訪
此處,享受尊榮服務 ☜
如果回覆對您有幫助,請記得按下「
標示為解答」。
在本討論區使用正體中文(即繁體中文),是對參與的朋友的一種尊重,因此請用本討論區的語言:正體中文。 -
2010年6月17日 上午 07:38
可是您所舉的那篇是問搜尋後 rename
所以他只要跑到
New-Item $newFile -type file
而我是要call外部的exe
所以問題不太一樣
以前用C++寫過類似的東西
但是code忘記放到哪裡了
所以才在想
PowerShell是否能夠更簡單的做到類似功能
而不用像C++還要用Win32API去寫個檔案搜尋與遞回處理的程式
抱歉
比較呆
Orz
player -
2010年6月17日 上午 09:11
找到了
用 Start-Process
參考
http://social.technet.microsoft.com/Forums/en-GB/ITCG/thread/98ce26e7-f320-4c2c-a060-ff7c106deb4a
player -
2010年6月17日 上午 09:36
C:\work\code>powershell -file C:\work\code\tool.ps1
C:\work\code\tool.ps1 檔案無法載入,因為這個系統上已停用指令碼執行。如需
詳細資訊,請參閱 "get-help about_signing"。
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordE
xception
+ FullyQualifiedErrorId : RuntimeException
這有解嗎?
頭好痛
player -
2010年6月17日 上午 10:04PowerShell V1
沒有 Start-Process 這種東西?
Orz
player -
2010年6月17日 上午 10:30失敗, 它不會搜尋子目錄, 誰知道該怎麼改?
$path = "C:\work\code\1"
$path2 = "C:\work\code\2"
$files = Get-ChildItem $path -Filter "*.txt" | Sort-Object -Property name
foreach ($file in $files)
{
$newFile = $path2 + "\" + $file.Name.Substring(0, $file.Name.Length -3) + "txt"
$msbuild = "C:\work\code\tool.exe"
$args = $path+"\"+$file+" "+$newFile
start-process $msbuild $args
}
player -
2010年6月21日 上午 01:20
看了您的程式碼之後,覺得您沒有完全理解參考資料中的程式碼,以下面的程式碼為例,會使用記事本開啟 D:\AlexChuo (含子目錄)目錄中,附檔名為 .txt 檔案:$cmd = "C:\Windows\system32\notepad.exe"
已經有了雛形,相信您已經知道要如何改成您要的了。
$path = "D:\AlexChuo"
$files = Get-ChildItem $path -Recurse -Filter "*.txt"
foreach ($file in $files)
{
& $cmd $file.FullName
}
☞ 這裡是「免費的討論區」,付費支援服務請造訪
此處,享受尊榮服務 ☜
如果回覆對您有幫助,請記得按下「
標示為解答」。
在本討論區使用正體中文(即繁體中文),是對參與的朋友的一種尊重,因此請用本討論區的語言:正體中文。

