Organize files in a specified directory by sorting them into categorized subdirectories (Images, Documents, Audio, Video, Archives, Code, Others).
Invoke with: /organize-files [path] [flags]
path: Target directory (default: current working directory)--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.json manifest)--exclude-ext / -e: Comma-separated extensions to skip (e.g. -e .tmp,.log)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 |
.file-organizer-log.json in the target directory (for --undo)Test-Path variant or try/catch).file-organizer-log.json itself.)photo (2).jpg)--dry-run must not modify any files--undo reads the manifest and moves each file back; delete the manifest on successful undo/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
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.
共 1 个版本