2013-10-07 87 views
0

我想寫下一個腳本,可以幫助我存檔多個子分區中的多個文件。另外我需要排除特定的文件。 到目前爲止,我得到了幾行腳本PowerShell腳本歸檔許多子文件夾中的文件

$files = Get-ChildItem -Recurse -path "D:\path\to\folder" -Exclude *i.jpeg | 
    Where-Object { $_.FullName -notmatch '\\excludedir($|\\)' } 
foreach ($file in $files) 
{ 
    C:\Program Files\7-zip\7z.exe" a -t7z -mx=9 -ms=on $file 
} 

基本上它的遞歸搜索所有子文件夾的.JPEG文,給我其中不包括結尾的那些「i'.jpeg讓我們說」名單photoi.jpeg 」。 這是工作,但我無法進入下一步,因爲我需要爲所有列出的文件運行7zip。

有人可以幫我在這裏。 感謝提前:)

回答

0

不知道,如果你想保存一個大的壓縮很多個別的,但我不喜歡這樣的:

Set-Alias sz "C:\Program Files\7-zip\7z.exe" 

$files = Get-ChildItem -Recurse -path "D:\path\to\folder" -Exclude *i.jpeg | 
    Where-Object { $_.FullName -notmatch '\\excludedir($|\\)' } 
foreach ($file in $files) 
{ 
    $output = sz a -t7z -mx=9 -ms=on "$File" 2>&1 
} 

您可能需要修改的壓縮和解線有我有使用命令行選項對其進行測試。另一個不錯的方面是我已經捕獲了用於報告目的的命令輸出。

0

您需要傳遞文件名,而不是對象,以7z命令。
@listfile語法可以幫助:

Get-ChildItem ...| Where-Object ...| select -expand fullname| out-file alist.txt -encoding utf8 
'C:\Program Files\7-zip\7z.exe' a archive.7z -mx=9 -ms=on `@alist.txt 
Remove-item .\alist.txt 

音符之前@反引號

相關問題