Powershell (YouTube .gig) Last File Hunter

In the course of creating just well it seems an AWFUL lot of .gig files, I realized I was very lazy and probably dumb. I’m also a very slow learner, so I like Powershell.

:drum: :drum:

Powershell is an easy way to access the innermost rings of the operating system which can be quite performant, particularly for doing file operations. Powershell Core I’m told can run on MacOS.

If you have Windows you can just search for “powershell” and embrace the cool blue command box.

I wanted to know which gig file was the latest I saved on a given date. I have not run a proper version control system for my gig files. Yes, I know I should. I’m just dumb enough to squeak past that test. I’m also so lazy all I want to do is copy the date of an item in my from my Youtube channel in whatever oddly sloppy format they use, like “3 Sept 2022” or “2 Jul 23” and have the last gig file I saved with that base name magically appear by the time my blink reopens my eyes. Yes, I am that lazy. I’m basically a Pixar sloth. My shame burns hot.

I’m so dumb,

HOW DUMB ARE YOU?

OK now you’re waking up a little, that’s good. I’m so dumb I spent more hours than I care to admit strong-arming Chat-GPT 3.5 and also a local Mistral MoE LLM I ran, into coming up with this script. The battle did not go well. But in the end I prevailed. Also “artificial” means “not,” which is why legal WILL NEVER allow marketing to un-bake it from being literally in the name.

This powershell script comes with all the usual Biblical-grade condemnations and severe warnings of famine, drought, random geese or other livestock and construction explosions, etc. Locust infestations, you name it we got it. It doesn’t write or change any file.

I’m so lazy I’m just going to paste it into one of these nifty code blocks.

param (
    [string]$DateString = $(Read-Host "Enter a date (format: '10 Sept 2021')")
)

# Split the date string into components
$dateComponents = $DateString -split ' '

# Extract day, month, and year
$day = [int]$dateComponents[0]
$month = $dateComponents[1]
$year = [int]$dateComponents[2]

# Convert month name to a numerical representation
$monthNumber = switch -Regex ($month) {
    'Jan' { 1 }
    'Feb' { 2 }
    'Mar' { 3 }
    'Apr' { 4 }
    'May' { 5 }
    'Jun' { 6 }
    'Jul' { 7 }
    'Aug' { 8 }
    'Sep' { 9 }
    'Oct' { 10 }
    'Nov' { 11 }
    'Dec' { 12 }
    default { throw "Invalid month: $month" }
}

# Construct a new DateTime object
$date = Get-Date -Year $year -Month $monthNumber -Day $day

# Filter files based on the specified date
$latestFile = Get-ChildItem -Path 'E:\Users\YourNameProbablyHere\Documents\' -Filter *.gig -Recurse | 
    Where-Object { $_.LastWriteTime.Date -eq $date.Date } | 
    Sort-Object LastWriteTime -Descending | 
    Select-Object -First 1

# Output the latest file
if ($latestFile) {
    $latestFile
} else {
    Write-Host "No files found with the specified date."
}

Huh.

Pro-tip you can actually just paste this into a blue Powershell window, hit enter and it ought to run, YMMV. Zero tech support offered. Already did that career.

By the time I’d gotten it to work I was shell-shocked enough that I was afraid to tell the robots to refactor it again. So edit the little path down there to suit your scenario, save it as I don’t know… go nuts:

gig-hunter.ps1

If you’re not familiar with powershell, don’t forget running it with the leading period and backslash or you’ll be sad, maybe for a few days I don’t know. I was.

.\gig-hunter.ps1

…and you’re off to the races. If you don’t include a date on the command line running it like this:

> .\gig-hunter.ps1 “14 Sept 2021”

It will at least ask politely if you forget, for a date like this:

> Enter a date (format: ‘10 Sept 2021’):

Everyone should be so polite after being turned down for a date.
:drum:

Only one this time? That’s how it’s going to be, OK. It’ll hunt down through all your subdirectories too. Yes I know it could be a lot better. Yes I know with one little change it could actually search for any filetype or wildcard at all. I may be dumb but at least my intelligence isn’t artificial. I’ll leave it as an exercise for the MacOS user to try having a GPT translate it into MacOS flavored BASH script should you be so inclined. Feel free, code warrior.

Us old people gotta stick together so I’ll close with this topical Silicon Valley parody of an actual traditional Irish blessing. Because Silicon valley… Unholy…

:drum:

I thought he’d never get here.

> May Gates and Altman never learn you aren’t even a C-class investor in OpenAI till a half an hour after the AGI singularity finds out you haven’t used Facebook since half an hour before Trudeau got in the first time.

(That one’s not going to land itself. Not without a rimshot. Don’t leave me hanging here.)

1 Like

:joy:

Having this post published and using the Powershell proves that you are not lazy, but maybe not motivated enough :smiley:

Yes but I learned a valuable lesson about how “artificial” really DOES MEAN “not.”