File Organizer Skill
Organize files in a specified directory by sorting them into categorized subdirectories (Images, Documents, Audio, Video, Archives, Code, Others).
Usage
Invoke with: /organize-files [path] [flags]
path: Target directory (default: current working directory)- Flags:
--dry-run/-d: Preview changes without moving files--flat/-f: Don't nest — move everything to current dir categories--undo: Move files back to their original locations (uses a.file-organizer-log.jsonmanifest)--exclude-ext/-e: Comma-separated extensions to skip (e.g.-e .tmp,.log)
File Categorization Rules
Extension matching is case-insensitive.
| Category | Extensions |
|---|---|
| Images | .jpg .jpeg .png .gif .bmp .svg .webp .ico .tiff .psd .raw |
| Documents | .pdf .doc .docx .xls .xlsx .ppt .pptx .txt .rtf .odt .ods .csv .md |
| Audio | .mp3 .wav .flac .aac .ogg .m4a .wma .opus |
| Video | .mp4 .avi .mkv .mov .wmv .flv .webm .mts |
| Archives | .zip .rar .7z .tar .gz .bz2 .xz .zst |
| Code | .py .js .ts .jsx .tsx .java .cpp .c .h .hpp .go .rs .swift .kt .scala .rb .php .pl .lua .sh .ps1 .bat .html .css .scss .less .sql .json .xml .yaml .yml .toml .ini .cfg .dockerfile .makefile .gradle |
| Executables | .exe .msi .dll .so .dylib .bin .appimage |
| Others | Everything not matched above |
Behavior
- Scan the target directory (non-recursive by default; only top-level files)
- Categorize each file by its extension
- Create category subdirectories if they don't exist
- Move files into corresponding directories
- Write a manifest file
.file-organizer-log.jsonin the target directory (for--undo) - Print a summary of what was moved
Safety
- Never move files that are currently open/locked (check with a
Test-Pathvariant or try/catch) - Never move
.file-organizer-log.jsonitself - Skip hidden files (starting with
.) - When moving, handle name collisions by appending a number suffix (e.g.
photo (2).jpg) --dry-runmust not modify any files--undoreads the manifest and moves each file back; delete the manifest on successful undo
Examples
/organize-files # organize the current directory
/organize-files D:\Downloads # organize a specific folder
/organize-files -d # preview only
/organize-files --exclude-ext .ini,.cfg # skip config files
/organize-files --undo # roll back the last organization
Implementation
Use PowerShell with the following helper approach:
$categories = @{
'Images' = @('.jpg','.jpeg','.png','.gif','.bmp','.svg','.webp','.ico','.tiff','.psd','.raw')
'Documents' = @('.pdf','.doc','.docx','.xls','.xlsx','.ppt','.pptx','.txt','.rtf','.odt','.ods','.csv','.md')
'Audio' = @('.mp3','.wav','.flac','.aac','.ogg','.m4a','.wma','.opus')
'Video' = @('.mp4','.avi','.mkv','.mov','.wmv','.flv','.webm','.mts')
'Archives' = @('.zip','.rar','.7z','.tar','.gz','.bz2','.xz','.zst')
'Code' = @('.py','.js','.ts','.jsx','.tsx','.java','.cpp','.c','.h','.hpp','.go','.rs','.swift','.kt','.scala','.rb','.php','.pl','.lua','.sh','.ps1','.bat','.html','.css','.scss','.less','.sql','.json','.xml','.yaml','.yml','.toml','.ini','.cfg','.dockerfile','.makefile','.gradle')
'Executables' = @('.exe','.msi','.dll','.so','.dylib','.bin','.appimage')
}
For each file: get extension, find matching category, create directory if needed, Move-Item with error handling. Write summary table.