Python... beats.... Battlestar Powershell

I had last written of my powershell explorations as it related to scouring excel files for certain values. Well, let me tell you… It’s garbage. I found that it would take several minutes to process even 10 files. Knowing I was up against many thousands, I had to regroup. And what I found was Python, and a pretty swell module called “openpyxl”.

By using this module, I was able to use some very efficient openxml based hooks to hammer through over 20,000 excel files and return the results within hours. Yes, it is helpful to know that modern Office files are essentially zip archives containing xml based document information, and that led to this python extension. By removing the need to use Excel directly, it when from 0 to 100 in speed, and what a life saver.

Here is the library and accompanying info: Link

If you ever find yourself having to scan and list a lot of files quick, and they are office files, this is a no brainer.

I have the Power....shell

Not sure that’s what He-Man had in mind, but no bother. I do want to talk about the fact that AI is an incredible tool sometimes. Like a second brain if used correctly. Today I needed a script that would find excel files, and then scrub the file for cell contents matching a certain value.

I decided to give Co-Pilot that very prompt, and I’ll be damned if it didn’t deliver with stunning accuracy. It even correctly interpreted my ask to output the matches in a specific format.

I did make a change or two to be fair. But it mostly hit it dead on the nail.

# Define the volume to search (e.g., "D:\")
$volumePath = Read-Host "Enter Folder Path"
# Define the pattern to search for
$pattern = "=NL()-"
# Define the list to store matching file paths
$matchingFiles = @()

# Get all Excel files recursively
$excelFiles = Get-ChildItem -Path $volumePath -Recurse -Include *.xlsx, *.xlsm, *.xls -ErrorAction SilentlyContinue

foreach ($file in $excelFiles) {
    try {
        # Open the Excel file using COM object
        $excel = New-Object -ComObject Excel.Application
        $excel.Visible = $false
        $workbook = $excel.Workbooks.Open($file.FullName, $null, $true)

        foreach ($sheet in $workbook.Sheets) {
            $usedRange = $sheet.UsedRange
            foreach ($cell in $usedRange.Cells) {
                if ($cell.Text -like "*$pattern*") {
                    $matchingFiles += $file.FullName
                    break
                }
            }
        }

        $workbook.Close($false)
        $excel.Quit()
        [System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel) | Out-Null
    } catch {
        Write-Warning "Failed to process $($file.FullName): $_"
    }
}

# Output the matching file paths
$matchingFiles | Out-File "MatchingExcelFiles.txt"
Write-Host "Matching files saved to MatchingExcelFiles.txt"

Multi Hobbyist

In my lifetime, I’ve described myself as having ever changing hobbies. It often seems that way, but on my morning commute today, I was considering the fact that I recently turned 44, and I began to consider my interests in those years and I arrived at an interesting conclusion.

What I have noticed is that my focus changes sometimes, but my core interests have remained relatively unchanged. If I had to list my hobbies, I think I can safely say that none of them are new. I will now attempt to list the hobbies I have developed over the years:

  • Music: Playing and Listening. I have been at this since I was but a wee child.

  • Golf: I started getting really into golf around 7th grade (Long time ago). Disc golf about 5 years ago. I still love them both.

  • Photography: I began to really get into photography in about 2003, and have continued to have an interest for it since. If it was feasable, I still think I’d really enjoy being a professional photo journalist.

  • Legos: I have enjoyed Legos since I was a child, and now that I am older and I can get some of the bigger sets, I enjoy them even more.

  • Mountain Biking: I can take the L here, but I have always wanted to get into this, and have just failed to dedicate the time to it.

As I sit back and look at it, this is such a normal list of hobbies. It seems like these are core hobbies for anyone that fits in my demographic.Of course, I am a huge tech guy, but that is my job, and so I can’t really call that a hobby.

Speaking of varying focuses, I have recently been feeling the photography vibes, and as I’ve posted about before, I seem to have really let the technology of it all pass me by in recent years. I have questioned the advantages of mirrorless setups, but as I look at them more, the advantages seem to be piling up. One major advantage is low light auto focus, but burst rates and speed, as well as AI enhanced Auto-Focus seem to be game changers as well.

I previously had a Fuji X100F - and I ended up parting with it, though to be honest I don’t know what I was thinking. I kind of miss that thing, and I’ve been finding myself wanting that Fuji vibe back in my life. One thing I didn’t love with the X100 is that it’s a 35mm focal length. Recently, Fuji has released the X-E5, and the X-T5 is also out. Both have similar specs, interchangeable lenses, and still offer the other fun parts of the Fuji world.

I am going to keep an eye out for the X-E5 and try to find a deal on the 23mm f/2 for it. But I may also be able to snag an X-T5 (or x-T4) for a deal on the used market. The smaller form factor and more street focused aesthetic made everything feel a bit more fun, and less intrusive.

We’ll see how things play out.

Maybe the newest Addition?

It’s hard to argue with this vibe on the new Fujifilm X-E5.