Created
February 23, 2025 21:25
-
-
Save mikkohei13/50daa01ce58ec5ae1a18d4053982a2a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PowerShell script for Windows. | |
# This script finds directories with 10 or more photos in them, | |
# matching the patterns used by digital camera: IMG_, DSC_, or DSCN. | |
param( | |
[Parameter(Mandatory=$true)] | |
[string]$DirectoryPath | |
) | |
# Verify the directory exists | |
if (-not (Test-Path -Path $DirectoryPath -PathType Container)) { | |
Write-Error "Directory not found: $DirectoryPath" | |
exit 1 | |
} | |
# Get all directories recursively | |
$directories = Get-ChildItem -Path $DirectoryPath -Directory -Recurse | |
$totalDirs = $directories.Count | |
$currentDir = 0 | |
foreach ($dir in $directories) { | |
$currentDir++ | |
# Show progress | |
Write-Progress -Activity "Scanning for photo directories" ` | |
-Status "Checking $($dir.FullName)" ` | |
-PercentComplete (($currentDir / $totalDirs) * 100) | |
# Count files matching the photo patterns in current directory | |
$photoCount = (Get-ChildItem -Path $dir.FullName -File | | |
Where-Object { $_.Name -match "IMG_|DSC_|DSCN" }).Count | |
# If directory has 10 or more matching files, output its path | |
if ($photoCount -ge 10) { | |
Write-Output "$photoCount photos: $($dir.FullName)" | |
} | |
} | |
# Clear the progress bar when done | |
Write-Progress -Activity "Scanning for photo directories" -Completed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment