2015-06-29 67 views
0

我正在嘗試將表批量導入到SQL中。爲此,我需要打開一個主目錄,然後遍歷這些子目錄來執行實際的文件。我似乎無法將這些子目錄名稱存儲在列表中。在列表中存儲目錄名稱並顯示

這裏是我的代碼:

$path = "E:\Dictionary_SQL_Commands\"; 
$i = 0; 

#I would like to dynamically allocate this space as I do not know the length 
$global:contents = new-object object[] 10; 

foreach ($item in $path){ 
    $global:contents[$i] = $local:item.name; 
    $i++; 
} 

$contents被創建,我可以用它查看gci variable:但輸出爲{$null,$null,...}

回答

2

你不需要一個「列表」。這是Powershell。

# Get all File items in the given path recursively # 
Get-ChildItem -Path:$path -Recurse -File | 
# Process each one as it's available # 
    Foreach-Object { 
     # Get the contents of each file # 
     $Contents = Get-Content $_; 
     # do other stuff with $Contents here # 
    } 

這是PowerShell的pipeline

+0

「你並不需要一個 」清單「,這是PowerShell的。」啊......我知道了。謝謝! @Eris – CRa

相關問題