サイズが数 KB から数 MB までさまざまな 700 万の XML ファイルを含むセットアップがあります。全体として、約 180 GB の XML ファイルです。私が実行する必要がある仕事は、各 XML ファイルを分析し、ファイルに string が含まれているかどうか、<ref>
現在含まれている Chunk フォルダーから Referenceless フォルダーに移動しないかどうかを判断することです。
私が作成したスクリプトは十分に機能しますが、私の目的には非常に遅いです。毎秒約 3 ファイルの速度で、約 24 日で 700 万ファイルすべての分析を終了する予定です。パフォーマンスを向上させるためにスクリプトを変更できるものはありますか?
また、問題をさらに複雑にしているのは、サーバー ボックスで .PS1 ファイルを実行するための適切なアクセス許可がないため、PowerShell から 1 つのコマンドでスクリプトを実行できる必要があることです。権限があれば、権限を設定します。
# This script will iterate through the Chunk folders, removing pages that contain no
# references and putting them into the Referenceless folder.
# Change this variable to start the program on a different chunk. This is the first
# command to be run in Windows PowerShell.
$chunknumber = 1
#This while loop is the second command to be run in Windows PowerShell. It will stop after completing Chunk 113.
while($chunknumber -le 113){
#Jumps the terminal to the correct folder.
cd C:\Wiki_Pages
#Creates an index for the chunk being worked on.
$items = Get-ChildItem -Path "Chunk_$chunknumber"
echo "Chunk $chunknumber Indexed"
#Jumps to chunk folder.
cd C:\Wiki_Pages\Chunk_$chunknumber
#Loops through the index. Each entry is one of the pages.
foreach ($page in $items){
#Creates a variable holding the page's content.
$content = Get-Content $page
#If the page has a reference, then it's echoed.
if($content | Select-String "<ref>" -quiet){echo "Referenced!"}
#if the page doesn't have a reference, it's copied to Referenceless then deleted.
else{
Copy-Item $page C:\Wiki_Pages\Referenceless -force
Remove-Item $page -force
echo "Moved to Referenceless!"
}
}
#The chunk number is increased by one and the cycle continues.
$chunknumber = $chunknumber + 1
}
私は PowerShell についてほとんど知識がありません。昨日、プログラムを開いたのは初めてでした。