Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #--- FolderDayQty.ps1 ---
- # Summarize the Last 15 File Dates and Counts
- #
- # This PowerShell searches the files in the passed folder and
- # groups the top 15 file dates sorted by date (decending),
- # the number of days ago it was from today, and
- # a count of the number of files on each date.
- #
- # Example output:
- # Days Media Date Files
- # 2 10/05/2024 Sat 97
- # 3 10/04/2024 Fri 23
- # 12 09/25/2024 Wed 20
- # 13 09/24/2024 Tue 5
- # 15 09/22/2024 Sun 40
- # 16 09/21/2024 Sat 5
- # 17 09/20/2024 Fri 39
- # 18 09/19/2024 Thu 10
- # 20 09/17/2024 Tue 1
- # 22 09/15/2024 Sun 10
- # 25 09/12/2024 Thu 6
- # 27 09/10/2024 Tue 3
- # 29 09/08/2024 Sun 4
- # 31 09/06/2024 Fri 1
- # 32 09/05/2024 Thu 5
- #
- # This output is followed by a prompt in the calling batch file
- # asking the user how may days ago to include in the archive
- # process. The Maxto M3 helmet camera is like a DVR so it
- # continuously records and deletes old files as space is needed.
- # The batch file copies recordings from the camera card to a hard
- # drive. This output helps the user decide how far back the
- # archive should go. If the user picks more days than necessary,
- # those days are still attempted to xcopy if they don't already
- # exist. (It doesn't hurt anything but it wastes time.) The
- # calling batch file will create an archive folder for each media
- # date so files are grouped by recording date.
- #
- # Shared online: https://pastebin.com/KwZQk3uh
- # https://www.facebook.com/groups/maxtom3/posts/7992261460846946/
- # This is used by Archive_M3_MOVIE_EF.bat, https://pastebin.com/LT5XESs0
- # File generated with Phind.com AI
- # Configured by Ben Sacherich - 11/19/2023 - https://www.facebook.com/groups/maxtom3
- # BS 1/28/2024 Updated to sort dates as dates and not as strings.
- # BS 10/7/2024 Added day of week "ddd" to the output and updated comments.
- #
- param(
- [string]$SourceFolder = ""
- )
- # $SourceFolder = "F:\CARDV\PHOTO"
- if (-not (Test-Path $SourceFolder -PathType Container)) {
- Write-Host "Source folder not found: $SourceFolder"
- exit 1
- }
- # Get all files in the source folder
- $files = Get-ChildItem -Path $SourceFolder
- # Create a hashtable to store counts based on date
- $dateCounts = @{}
- # Loop through each file
- foreach ($file in $files) {
- # Get the date without the time
- $date = $file.LastWriteTime.Date
- # Write-Host $date
- # Check if the date is already in the hashtable
- if ($dateCounts.ContainsKey($date)) {
- # Increment the count for the date
- $dateCounts[$date]++
- } else {
- # Add the date to the hashtable with a count of 1
- $dateCounts[$date] = 1
- }
- }
- # Sort the hashtable by keys in descending order
- $sortedDates = $dateCounts.GetEnumerator() | Sort-Object -Property Name -Descending
- # Select the top 15 dates
- $top5Dates = $sortedDates | Select-Object -First 15
- # Display the counts for these dates and the number of days back they are from today
- Write-Host "Days`tMedia Date`tFiles"
- foreach ($date in $top5Dates) {
- $count = $dateCounts[$date.Name]
- $daysBack = (Get-Date).Subtract($date.Name).Days
- Write-Host "$daysBack`t$($date.Name.ToString('MM/dd/yyyy ddd'))`t$count"
- }
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement