2013-10-28 35 views
0

我已經繼承並正在運行下面的Powershell腳本,並且我正在解釋它並將其一些功能應用於我正在編寫的其他腳本中。

特別,我期待在下面的代碼行:

ForEach ($doc in $srcfiles) { 
saveas-document -docs $doc 
} 

從程序的功能,我知道,在$srcfiles文檔的每個實例被賦值給變量$doc,那將變量傳遞給saveas-document函數作爲輸入值。不過,我不確定$doc是從哪裏來的。這個聲明是否在運行中聲明$doc變量?或者它是一個Powershell保留字代表我的源代碼路徑中的文檔對象?另外,-docs交換機在dessence聲明$doc等於函數期望的變量?我需要一些幫助來理解它是如何工作的,以便我可以將這些知識應用於其他項目。

$global:word = new-object -comobject word.application 
$word.Visible = $False 
# PATHS 
$backupPath = "\\Server\path\to\source\files\" 
$srcfiles  = Get-ChildItem $backupPath -filter "*htm.*" 
$dPath   = "\\Server\path\to\desitination\files\"  
$htmPath  = $dPath + "HT\"  # Data path for HTML 
$docPath  = $dPath + "DO\"  # Data path for *.DOC 
$doxPath  = $dPath + "DX\"  # Data path for *.DOCX 
$txtPath  = $dPath + "TX\"  # Data path for *.TXT 
$rtfPath  = $dPath + "RT\"  # Data path for *.RTF 
# SAVE FORMATS 
$saveFormatDoc = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], 0); 
$saveFormatTxt = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], 4); 
$saveFormatRTF = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], 6); 
$saveFormatDox = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], 16); 
$saveFormatXML = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], 14); 
# Convert Documents 
function saveas-document ($docs) {    
    $savepath = "$docPath$($docs.BaseName)" 
    "Converting to $savepath.doc"  
    $opendoc.saveas([ref]"$savepath", [ref]$saveFormatDoc) 
    $opendoc.close()  
    "Success with conversions." 
    " " 
} 
# 
ForEach ($doc in $srcfiles) { 
saveas-document -docs $doc 
} 
# 
$word.quit() 

回答

1

運行follwing命令,並通過輸出讀:

Get-Help about_foreach -ShowWindow 
Get-Help about_functions -ShowWindow 
相關問題