#使用shell.application開啟檔案
$shell = New-Object -com shell.application
#取出d:\test0401之下一層的資料及資料夾
$foldersandFiles = $shell.NameSpace("d:\test0401")
#列舉每筆資料,記得要.items()
foreach($a in $foldersandFiles.items())
{

  #開啟檔案
  $a.InvokeVerbEx("edit")
}

#若要讀取陣列中的某個資料
則必須使用
$Sets = $foldersandFiles.Items()
$Sets.Item(index)
例如:
$Sets.item(0).InvokeVerbEx("edit")


以上方法相當的煩瑣
若是使用PowerShell的Cmdlet則是相當的方便啊,只要一行而已(連資料夾都幫你打開喔)
dir d:\test0401 | foreach{invoke-item $_.fullName}

 


 

參考資料:http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct04/hey1004.mspx

arrow
arrow
    全站熱搜

    ayowu 發表在 痞客邦 留言(0) 人氣()