我想比较我的数组列表(文件夹中每个文件的文件名)和包含丢失文件的日志文件。 (例如,在文件夹中我们有24个文件,让我们说我们有01.csv,03.csv 04.csv和06.csv,缺少的文件是02.csv和05.csv我要做什么来复制01 .csv或03.csv,如果文件丢失是02.csv等等)如果你有任何想法会使它变得简单。请帮忙! 这是我的脚本,到目前为止我已经完成了随机获取文件夹中的可用文件以提供丢失的文件。
$folder="D:\ERM\Dump_files\Hourly\RTDEG"
$RTDEG = @("rtdeg_$RTDEG_01", "rtdeg_$RTDEG_02", "rtdeg_$RTDEG_03",
"rtdeg_$RTDEG_04", "rtdeg_$RTDEG_05", "rtdeg_$RTDEG_06",
"rtdeg_$RTDEG_07", "rtdeg_$RTDEG_08", "rtdeg_$RTDEG_09",
"rtdeg_$RTDEG_10", "rtdeg_$RTDEG_11", "rtdeg_$RTDEG_12",
"rtdeg_$RTDEG_13", "rtdeg_$RTDEG_14",
"rtdeg_$RTDEG_15","rtdeg_$RTDEG_16",
"rtdeg_$RTDEG_17", "rtdeg_$RTDEG_18", "rtdeg_$RTDEG_19",
"rtdeg_$RTDEG_20", "rtdeg_$RTDEG_21", "rtdeg_$RTDEG_22",
"rtdeg_$RTDEG_23", "rtdeg_$RTDEG_24")
$files = Get-ChildItem $folder -recurse -Exclude "*.txt", "*.log" |
Where-Object {($_.CreationTime -gt (Get-Date).adddays(-4))}
if((Get-ChildItem "D:\ERM\Dump_files\Hourly\RTDEG" -Exclude "*.txt",
"*.log" | Measure-Object -line).lines -ge 24){
echo "Viola! No missing files."
}else{
echo "Validating the missing files."
$files.Basename | Out-File $folder\validation.txt
$fileRTDEG = $files | ForEach-Object { ($_.BaseName) }
set-Content $folder\validated.txt -value "Missing"
Compare-Object $RTDEG $fileRTDEG | select -ExpandProperty InputObject |
Out- File $folder\validated.txt -Append ascii
$compare = import-csv $folder\validated.txt
foreach($missed in $compare){
$data = $missed.Missing
$random = gci $folder -Exclude "*.txt", "*.log" | where {$_.psIsContainer -
eq $false}| Resolve-Path | Get-Random -Count 1
Copy-Item $random -Destination $folder\$data.csv
}}
我也想制作一个循环来提供数组。但我不认为我做得对。这是我的代码:
$RTDEG = @()
for ($i = 01; $i -le 24; $i ++){
$date = (Get-Date).adddays(-4).ToString("yyyyMMdd")
$list = "rtdeg_" + "" + $date + "" + $i.ToString("00")
Write-Output $RTDEG
}