Package: auto-file-sorter
auto-file-sorterauto-file-sorteris a Python automation tool that tracks a directory and sorts files into their respective folders based on their file extensions.InstallationMake sure you have Python 3.9 or later installed. You can install the package usingpip:pipinstallauto-file-sorterAlternatively, you can install the package from GitHub to get the latest changes:pipinstallgit+https://github.com/realshouzy/auto-file-sorter.gitThe project uses the following packages and libraries:# standard libraryimportargparseimportconcurrent.futuresimportdatetimeimportjsonimportloggingimportos.pathimportpathlibimportplatformimportreimportshutilimportsysimporttimeimporttyping# third partyimporttyping_extensions# import watchdogimportwatchdog.eventsimportwatchdog.observers# only for type annotations; not used at runtimeimportcollections.abcimportwatchdog.observers.api# for testingimportpytestDocumentationConsultauto-file-sorter --help/auto-file-sorter -hfor the full set of options. This also applies to all subcommands:auto-file-sorter trackauto-file-sorter readauto-file-sorter writeauto-file-sorter locationsArguments and flags ofauto-file-sorterArgument and flagsUse--version/-VOutputs the installed version ofauto-file-sorter.--debug/-dSets the logging level to 10 (debugging), enabling more informative debugging logs.--verbose/-vEnables verbose outputs. It can be used up to three levels, with each level printing more logs to the stream. The first level prints all logs up to the logging level WARNING, the second level prints all logs up to INFO, and the third level prints all logs up to DEBUG (this requires the debugging flag).--log-locationSpecifies the path to a log file. By default, the log file will be located with the source code.--configs-locationSpecifies the path to the configsjsonfile. By default, the configs file will be located with the source code.Arguments and flags ofauto-file-sorter trackArgument and flagsUsePositional argumentsPaths to the directories to be tracked. At least one directory path must be provided. The tool will track all the given directories simultaneously using threading.--undefined-extensions/-uPath in which files whose extensions are not defined in the configs will be moved. If no path was specified, said files will be skipped.--autostart(only supported on Windows)Runs the command on startup. Refer toWindows setupfor more information.Arguments ofauto-file-sorter readArgumentUsePositional argumentsExtensions for which their respective paths should be read from the configs.json file. If no extensions are given, it will print out the entireconfigs.jsonfile.Arguments ofauto-file-sorter writeArgumentUse--add/-aAdds an extension and its corresponding path to theconfigs.jsonfile. It takes two arguments: the extension and the path to which files with this extension will be saved. If the extension already exists, the path will be overridden.--remove/-rRemoves one or more extensions and their respective paths from the configuration.--json/-jLoads ajsonfiles that binds extensions to paths and merges it into theconfigs.jsonfile.The json files should be structured similarly to theconfigs.jsonfile. An example (with Windows paths) can be found inexample_configs.json.
Ultimately you can directly modify theconfigs.jsonfile yourself.Flags ofauto-file-sorter locationsArgumentUse--log/-lPrints the location of the log file--config/-cPrints the location of the config fileRun on startupWindows setupTo run the tool on startup, add the--autostartflag after thetracksubcommand. This will add the command to the Startup folder as a.vbsfile, ensuring it runs in the background.To avoid the overhead of creating a StreamHandler and prevent overwriting the.vbsfile on every startup, it removes all occurrences of--verbose/-vas well as--autostart.An example of this transformation:- auto-file-sorter -d -vvv track C:\path\to\be\tracked+ C:\path\to\auto-file-sorter.exe -d track C:\path\to\be\trackedThis will then be run by the.vbsfile on startup:Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "C:\path\to\auto-file-sorter.exe -d track C:\path\to\be\tracked", 0, TruemacOS setupAdd the desired command to theAutomatorapp. You can find a tutorialhere.Linux setupDue to the wide variety of Linux distributions and their differences, it is up to the user to configureauto-file-sorterto run on startup.UsageSimply place files into the tracked folder, and the tool will automatically sort them for you.Excpetion handlingMost exceptions will be logged in a log file. If an exception should occur, the program will handle it gracefuly by exiting with exit code 1, except in cases where an exception is encountered while moving a file. This behavior is specifically implemented to address threading concerns and ensure proper garbage collection. In such cases, the respective thread will exit, while the main program continues its execution. Ultimately, the user has the option to stop the program manually. This approach allows for proper cleanup and termination of resources.ContributingIf you are interested in contributing to this project, please referherefor more information.Licenseauto-file-sorteris available under theMIT licenseCreditThis project was originally inspired by Kalle Hallden'sdesktop_cleanerproject.