Level up my file management workflow

As someone who does contract work on the computer, I’m constantly looking for ways to do things faster and easier. There are no rewards for working “hard” when it’s possible to work smart. Additionally, a great way to make the work you do rewarding is to automate the tedious stuff so you can have more time doing what you enjoy. One of the most tedious aspects of computer work is file management. Lately, I’ve decided to level up my file management workflow (as evidenced by my recent music organization efforts.) This means spending a little time upfront to save a bunch of time down the road.

If you are someone who:

  • deals with a lot of files
  • has repetitive file management tasks—particularly for work

… then maybe it’s time to level up your file explorer game as well.

For me, this has come in the form of Directory Opus 13 (aka ‘dopus’). If you’re a Windows user, think of Dopus as a super-duper file explorer. It allows for infinite customization, special views, scripts—more features than I could possibly cover here. Instead of trying to capture all the things Dopus does, I want to share a specific use case that has worked for me.

If you’re reading this, I betcha you have a ‘downloads’ folder that is a mess. It’s probably full of years of old files, things you’ve been meaning to get to—who knows! Mine was like that too. One day, I realized that my downloads folder was a mess of stuff that I don’t have time to sort through but also am tired of staring at. I finally decided to do something about it.

Using AI, I decided to build a script in Dopus that would automatically keep my downloads folder clean. The goal was to build a script that would take anything over two weeks old and organize it into a folder by type. If the folders don’t exist, it’ll make them. The folders are color coded and will highlight when a new file is received.

After a bit of back and forth with AI, I finally got a script that does all the things I wanted it to do. The result is a downloads folder that looks like this:

A few spare folders aside, this is a pretty clean downloads folder. There’s one file I downloaded yesterday, but the rest of the files have been organized into folders by type to be forgotten forever sorted through at a later date. From a behavior modification standpoint, I’ve also found that this causes me to actually address downloads more proactively than I have in the past.

If you’re already a Dopus user or think you might be one in the future, here’s the script for you below. It includes instructions for adapting it to your file system. Feel free to modify it as needed, but please leave the header in place so I can retain some credit. Enjoy!

JavaScript
// ========================================================================
// Downloads Organizer for Directory Opus
// ========================================================================
// Created by: Berkeley Goodloe
// Last Updated: July 4, 2025
// Version: 1.4
// Contact: [email protected]
// 
// This script was coded mostly with the Claude Sonnet 4 Think AI model and a little bit with
// the Claude Sonnet 3.7 Think model.
//
// DESCRIPTION:
// Automatically organizes files in your Downloads folder based on file type
// and age. Files older than 2 weeks are sorted into category folders with
// status indicators to show which folders have recently received files.
//
// CONFIGURATION:
// To adapt this script for your own use:
// 1) Set your downloads path in the variable below (look for "SET YOUR DOWNLOADS PATH HERE")
// 2) The script uses two status labels: "archive" and "archive (recent update)"
//    Make sure these status labels exist in your Directory Opus configuration
//    or change them to your preferred labels (look for "STATUS LABEL" comments)
//
// The script handles these file categories:
// - Images: jpg, jpeg, png, bmp, gif, tiff
// - Videos: mp4, avi, mkv, mov, wmv, flv, webm
// - Audio: mp3, flac, aac, ogg
// - Documents: pdf, doc, docx, xls, xlsx, ppt, pptx, txt, csv
// - Archives: zip, rar, 7z, tar, gz
// - Music Production: mid, wav, amxd
// - Other: anything else
// ========================================================================

var g_lastRunTime = 0;
var g_isRunning = false;

function OnInit(initData)
{
    initData.name = "Downloads Organizer Clean";
    initData.version = "1.4";
    initData.copyright = "(c) 2025 berke";
    initData.desc = "Clean auto-organizer with folder status indicators";
    initData.default_enable = true;
    initData.min_version = "13.0";
}

function isInCategory(ext, categoryArray) {
    for (var i = 0; i < categoryArray.length; i++) {
        if (categoryArray[i] === ext) {
            return true;
        }
    }
    return false;
}

function getObjectKeyCount(obj) {
    var count = 0;
    for (var key in obj) {
        if (obj.hasOwnProperty(key)) {
            count++;
        }
    }
    return count;
}

function OnSourceDestChange(sourceDestChangeData)
{
    // *** SET YOUR DOWNLOADS PATH HERE ***
    // Change this to your own downloads folder path
    var downloadsFolderPath = "E:\\Downloads";
    var currentPath = String(sourceDestChangeData.tab.path);
    
    // SAFETY CHECKS
    var now = new Date().getTime();
    
    if (currentPath !== downloadsFolderPath) return;
    if (g_isRunning) return;
    if (now - g_lastRunTime < 5000) return;
    
    g_isRunning = true;
    g_lastRunTime = now;
    
    try {
        // Extension groups
        var images = ["jpg", "jpeg", "png", "bmp", "gif", "tiff"];
        var videos = ["mp4", "avi", "mkv", "mov", "wmv", "flv", "webm"];
        var audio = ["mp3", "flac", "aac", "ogg"];
        var documents = ["pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "txt", "csv"];
        var archives = ["zip", "rar", "7z", "tar", "gz"];
        var musicProduction = ["mid", "wav", "amxd"];
        
        // Define the managed category folder names - ONLY THESE WILL BE TOUCHED!
        var managedCategories = [
            "images", 
            "videos", 
            "audio", 
            "documents", 
            "archives", 
            "music production files", 
            "other assorted older files"
        ];
        
        // Calculate threshold date (2 weeks ago)
        var oldThreshold = new Date();
        oldThreshold.setDate(oldThreshold.getDate() - 14);
        
        var FSUtil = DOpus.FSUtil;
        var FolderEnum = FSUtil.ReadDir(downloadsFolderPath);
        var categories = {};
        var foldersToCreate = [];
        
        // Categorize files
        while (!FolderEnum.complete) {
            var entry = FolderEnum.Next();
            if (entry.is_dir) continue;
            
            var modDate = new Date(entry.modify);
            if (modDate < oldThreshold) {
                var ext = String(entry.ext).toLowerCase().replace(".", "");
                var destFolder = "";
                
                if (isInCategory(ext, musicProduction)) destFolder = "music production files";
                else if (isInCategory(ext, images)) destFolder = "images";
                else if (isInCategory(ext, videos)) destFolder = "videos";
                else if (isInCategory(ext, audio)) destFolder = "audio";
                else if (isInCategory(ext, documents)) destFolder = "documents";
                else if (isInCategory(ext, archives)) destFolder = "archives";
                else destFolder = "other assorted older files";
                
                if (!categories[destFolder]) {
                    categories[destFolder] = [];
                    foldersToCreate.push(destFolder);
                }
                categories[destFolder].push(entry.name);
            }
        }
        
        if (foldersToCreate.length === 0) {
            DOpus.Output("📁 Downloads folder is clean (no files older than 2 weeks)");
        } else {
            DOpus.Output("🗂️ Downloads Organizer: Processing " + getObjectKeyCount(categories) + " categories...");
            
            // Create folders
            var cmd = DOpus.Create.Command();
            cmd.SetSourceTab(sourceDestChangeData.tab);
            
            for (var i = 0; i < foldersToCreate.length; i++) {
                var folderName = foldersToCreate[i];
                var fullFolderPath = downloadsFolderPath + "\\" + folderName;
                
                if (!FSUtil.Exists(fullFolderPath)) {
                    cmd.RunCommand('CreateFolder NAME="' + folderName + '" READAUTO=no');
                }
            }
            
            // Track which folders receive files in this run
            var foldersWithNewFiles = {};
            
            // Move files
            var totalMoved = 0;
            var totalErrors = 0;
            
            for (var category in categories) {
                var fileList = categories[category];
                var destPath = downloadsFolderPath + "\\" + category;
                var filesMoved = 0;
                
                for (var j = 0; j < fileList.length; j++) {
                    try {
                        cmd.RunCommand('Copy MOVE "' + fileList[j] + '" TO "' + destPath + '"');
                        totalMoved++;
                        filesMoved++;
                    } catch(e) {
                        DOpus.Output("❌ Failed to move: " + fileList[j]);
                        totalErrors++;
                    }
                }
                
                // If any files were moved to this folder, mark it for status update
                if (filesMoved > 0) {
                    foldersWithNewFiles[category] = true;
                    DOpus.Output("📊 Marked for status update: " + category + " (moved " + filesMoved + " files)");
                }
            }
            
            // Summary
            if (totalMoved > 0) {
                DOpus.Output("✅ Organized " + totalMoved + " files into " + getObjectKeyCount(categories) + " categories" + 
                           (totalErrors > 0 ? " (" + totalErrors + " errors)" : ""));
                
                // Update folder statuses
                DOpus.Output("🔄 Updating folder statuses...");
                
                try {
                    var tab = sourceDestChangeData.tab;
                    
                    // First set all MANAGED category folders to default "archive" status
                    for (var i = 0; i < managedCategories.length; i++) {
                        var folderName = managedCategories[i];
                        var folderPath = downloadsFolderPath + "\\" + folderName;
                        
                        // Skip if folder doesn't exist
                        if (!FSUtil.Exists(folderPath)) {
                            DOpus.Output("⚠️ Folder doesn't exist, skipping: " + folderName);
                            continue;
                        }
                        
                        var folderItem = DOpus.FSUtil.GetItem(folderPath);
                        
                        if (folderItem) {
                            var setArchiveCmd = DOpus.Create.Command();
                            setArchiveCmd.AddFile(folderItem);
                            // *** STATUS LABEL: Default archive status ***
                            setArchiveCmd.RunCommand("Properties SETLABEL archive");
                            DOpus.Output("📂 Set default status: " + folderName + " → archive");
                        }
                    }
                    
                    // Then update folders that received files to "archive (recent update)"
                    for (var folder in foldersWithNewFiles) {
                        if (foldersWithNewFiles.hasOwnProperty(folder)) {
                            var folderPath = downloadsFolderPath + "\\" + folder;
                            var folderItem = DOpus.FSUtil.GetItem(folderPath);
                            
                            if (folderItem) {
                                var setRecentCmd = DOpus.Create.Command();
                                setRecentCmd.AddFile(folderItem);
                                // *** STATUS LABEL: Recent update status ***
                                setRecentCmd.RunCommand("Properties SETLABEL \"archive (recent update)\"");
                                DOpus.Output("📂 Updated status: " + folder + " → archive (recent update)");
                            } else {
                                DOpus.Output("⚠️ Could not get folder item for: " + folder);
                            }
                        }
                    }
                    
                    // Force a refresh of the current tab
                    var refreshCmd = DOpus.Create.Command();
                    refreshCmd.SetSourceTab(tab);
                    refreshCmd.RunCommand('Go REFRESH');
                    
                } catch(statusError) {
                    DOpus.Output("❌ Error updating folder statuses: " + statusError.message);
                }
            }
        }
        
    } catch(e) {
        DOpus.Output("❌ Downloads Organizer Error: " + e.message);
    } finally {
        g_isRunning = false;
    }
}

Welcome

headshot portrait of Berkeley Goodloe

This is the personal homepage of
T. Berkeley Goodloe, where you’ll find writings on various current topics that I’m encountering, experiencing, or working on. This includes productivity, student success, and my attempts to analogize modular synthesis into everyday life.

Let’s connect