Claude (and ChatGPT) are useful for writing scripts in vaguely familiar scripting languages that I would otherwise spend [much more time] trying to piece together the correct syntax to write. And I can often get a reasonable first pass from a prompt on my phone, depending on how complicated the needs are. And regardless of the quality of the code, it’s generally closer to idiomatic code than if I pieced it together myself (again, for languages I’m familiar with but not expert in).
The latest example? Getting a listing of videos on a media server, making a basic attempt at title casing.
Prompt: Write powershell to format a list of mkv files in \\videos\media as a title cased list of filenames output to a text file
The results:
# Get all MKV files from the specified directory
$videoPath = "\\videos\media"
$outputFile = "formatted_mkv_list.txt"
# Check if the directory exists
if (-not (Test-Path $videoPath)) {
Write-Error "Directory $videoPath does not exist."
exit 1
}
# Get all .mkv files and format their names
$mkvFiles = Get-ChildItem -Path $videoPath -Filter "*.mkv" -File
if ($mkvFiles.Count -eq 0) {
Write-Warning "No MKV files found in $videoPath"
exit 0
}
# Process each file and convert to title case
$formattedNames = @()
foreach ($file in $mkvFiles) {
# Get filename without extension
$nameWithoutExt = [System.IO.Path]::GetFileNameWithoutExtension($file.Name)
# Convert to title case using TextInfo
$titleCase = (Get-Culture).TextInfo.ToTitleCase($nameWithoutExt.ToLower())
# Add to array
$formattedNames += $titleCase
}
# Sort the names alphabetically
$formattedNames = $formattedNames | Sort-Object
# Output to text file
$formattedNames | Out-File -FilePath $outputFile -Encoding UTF8
Write-Host "Formatted $($mkvFiles.Count) MKV filenames to '$outputFile'"
Write-Host "Files processed from: $videoPath"
One clarification that I should probably add to all of the above is that this code is in no way going to see a production setup anywhere. Also neglected in the task is the possibility that a media server might have a cleaner catalog already that I could’ve exported. But this worked for my needs. I find regular occasions for writing “good enough” scripts without additional editing. And LLMs keep me from overthinking a trivial application.