Skip to main content

Reworking a messy video archive with custom software.

If you’re a content creator, video editor, or developer, you know how quickly a project archive can spiral out of control. Over the years, my video project folders had become a chaotic mix of naming conventions. Some folders started with dates, some started with the camera name (like 500dollar-camera), and others were just random project titles. 

I decided it was time to standardize everything to a clean YYYYMMDD-ProjectName format. But with hundreds of folders, doing this manually wasn't a reasonable option.

Instead of writing the whole thing from scratch, I decided to pair-program the solution using Gemini Pro. This article details building a C# .NET 8 WinForms application, the bugs along the way, and how tools like this can speed up iterative development.


The Design Goals

Before writing code, I needed to define exactly what this application was going to do. I laid out the following rules for the renaming logic: 

  • The Target: Standardize folder names to YYYYMMDD-ProjectName.
  • The Skip Logic: If a folder already starts with an 8-digit date, skip it.
  • The Data Source: Look inside each folder for Vegas Pro project files (.vf or .veg). Extract the creation date of the oldest project file and use its filename as the new folder name.
  • The Fallback: If no Vegas files exist, find the oldest file of any type in that folder and use its date, keeping the original folder name text.
  • The UI: A clean, responsive interface with a progress bar, a status log window, and the ability to cancel the operation mid-run.


Tools & Tech Stack

  • Language: C#
  • Framework: .NET 8.0 (Windows Forms)
  • IDE: Visual Studio 2022
  • AI Assistant: Google Gemini Pro

The Blueprint: Setting Up the UI and Initial Prompt

The main form.

I built the UI myself in Visual Studio:

  • lblFolderSelectedDisplay: Shows the chosen target directory.
  • btnSelectFolderAndStart: Triggers the folder browser and starts the process.
  • btnCancelRenameProcess: Stops the background worker.
  • txtStatusDisplay: A multiline TextBox to log success, skips, and errors.
  • pbStatusBar: A visual progress indicator.
  • bwFolderRenamingProcess: A BackgroundWorker component to handle the heavy lifting without freezing the UI.

What is a BackgroundWorker?

In desktop application development, if you run a long, intensive task (like scanning hundreds of files) on the main user interface (UI) thread, the application will freeze and become unresponsive. The BackgroundWorker class in .NET executes an operation on a separate, dedicated background thread, allowing the UI to remain interactive and update progress bars smoothly. (Source: Microsoft .NET Documentation)

Once the UI was set, I wrote my initial prompt to Gemini Pro. I detailed the exact names of my UI controls, explained my folder naming logic, and outlined the Vegas Pro .vf and .veg file requirements.

Gemini implemented a helper class called ProgressReportUpdate to pass data safely back to the UI thread, and a SanitizeFolderName method to strip out invalid characters.


Bugs, Roadblocks, and Solutions

Working with an LLM is a conversation. Gemini provided the foundation, but as I tested the app on my actual drives, we ran into several edge cases that required iterative problem-solving.

Roadblock 1: The Ghost in the Machine (System Folders)

The Issue: During the first test run on the root of a drive, the program crashed with UnauthorizedAccessException errors. It was trying to access System Volume Information and $RECYCLE.BIN.

The Collaborative Fix: I pasted the error log back to Gemini. It immediately realized we had forgotten to filter out hidden and system-level directories. Gemini provided a quick fix using bitwise operators to check the DirectoryInfo.Attributes.

if ((dirInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden ||
    (dirInfo.Attributes & FileAttributes.System) == FileAttributes.System)
{
    // Skip this folder
    continue; 

}


Roadblock 2: The "Time Machine" Bug

There was a logical error: the app was renaming my folders using today's date instead of the historical file dates.

The Collaborative Fix: I told Gemini, "This isn't working right. It's using today's date instead of the creation date."

By having Gemini add detailed debug outputs to the status text box, we tracked down the culprit: Variable Scope. The variable DateTime oldestFileDate = DateTime.MaxValue; was originally declared outside the main loop. Once it found a date in the first folder, it wasn't resetting for the next one. We moved the initialization inside the for loop, ensuring a fresh calculation for every folder.


Roadblock 3: Date Created vs. Date Modified

The Issue: As we fixed the date logic, I realized a quirk of the Windows File System. Sometimes, if you copy a file from an old hard drive to a new one, Windows sets the "Date Created" to the day you copied it, but leaves the "Date Modified" as the original historical date. 

File Timestamps in Windows: It is a common misconception that "Date Created" is always the oldest date. If you copy a file to a new volume, the OS creates a new file entry, meaning CreationTime becomes the current date, while LastWriteTime (Modified) retains the historical timestamp. Robust file archiving tools should always check both and use the older of the two.

The Collaborative Fix: I prompted Gemini: "Let's use the date modified if the date created is newer."

Gemini updated our date extraction logic with a brilliant ternary operator to establish an "Effective Date" for every single file it scanned: 

DateTime effectiveFileDateForThisFile = fileInfo.CreationTimeUtc < fileInfo.LastWriteTimeUtc 

    ? fileInfo.CreationTimeUtc 

    : fileInfo.LastWriteTimeUtc;


Roadblock 4: The "500 Dollar Camera" Dilemma

The Issue: My original prompt told Gemini to "skip folders that already have at least one number at the start." Gemini implemented this using char.IsDigit(currentSubFolderName[0]).

This worked perfectly for folders like 20201008-Sigma-Lens, but it erroneously skipped folders like 500dollar-camera and 22mm-challenging-to-use-09092018.

The Collaborative Fix: I pointed this out to Gemini and suggested we only skip folders that start with exactly 8 digits (my YYYYMMDD format). Gemini removed the char.IsDigit check and introduced a Regular Expression (Regex).

if (Regex.IsMatch(currentSubFolderName, @"^\d{8}"))

{

    // Skip: Already formatted correctly

    continue;

}

What is Regex (^\d{8}) ?

  • A Regular Expression (Regex) is a sequence of characters that specifies a search pattern.
  • ^ asserts that we are at the beginning of the string.
  • \d matches any digit (0-9).
  • {8} specifies that exactly 8 digits must be matched.
  • Therefore, this pattern strictly looks for strings starting with an 8-digit block and nothing else.


The Final Results

With the core logic working, we added a few final touches. I suggested adding robust null checks at the start of the BackgroundWorker execution, and Gemini ensured that the pbStatusBar gracefully handled scenarios where a directory contained zero folders to process.


The Result:

The application successfully: 

  • Ignored my system files.
  • Skipped folders I had already organized.
  • Dug into old, unorganized folders.
  • Accurately pulled the oldest historical date from my Vegas .vf files (bypassing Windows copy-date bugs).
  • Renamed everything without a single data-loss collision.


Conclusion

Using these tools have changed how viable tasks like this are in a reasonable amount of time. I didn't have to spend hours writing boilerplate BackgroundWorker code or Googling DirectoryInfo syntax. I provided the architecture, the UI, and the domain knowledge. Gemini Pro handled most of the code writing.

The back-and-forth iteration is where some of the more basic free LLMs can work well. You don't need a perfect prompt on the first try as long as you use test data; you just need to know how to read the output, spot the logical flaws, and guide the AI toward the solution.