write a powershell script to count the number of PDF files within an array of multiple…
- User
write a powershell script to count the number of PDF files within an array of multiple subfolders, and write the output using Export-CSV. The output should consist of the folder name and the number of PDF files within each folder. Display a progress bar that indicates once for each subfolder.
- Assistant
Here is a PowerShell script that counts the number of PDF files within an array of multiple subfolders and writes the output to a CSV file using Export-CSV:
perl$folders = @("C:\Folder1", "C:\Folder2", "C:\Folder3") $results = @() Write-Progress -Activity "Counting PDF Files" -Status "In Progress" foreach ($folder in $folders) { $pdfFiles = Get-ChildItem -Path $folder -Filter *.pdf -Recurse | Measure-Object $pdfCount = $pdfFiles.Count $results += New-Object PSObject -Property @{ Folder = $folder PDF_Count = $pdfCount } Write-Progress -Activity "Counting PDF Files" -Status "$folder" -PercentComplete ($folders.IndexOf($folder) / $folders.Count * 100) } $results | Export-Csv -Path "C:\PDF_Count.csv" -NoTypeInformation Write-Progress -Activity "Counting PDF Files" -Status "Completed" -Completed Write-Output "Finished counting PDF files and exporting results to C:\PDF_Count.csv"
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.