Giter Site home page Giter Site logo

classifier's Introduction

Classifier

Organize files in your current directory, by classifying them into folders of music, pdfs, images, etc.

Installation

$ pip install classifier

Compatibility

  • Python 2.7 / Python 3.4
  • Linux / OSX / Windows

Usage

  • Go to your directory, where you want to classify your files.
  • Run the following command in your terminal.
$ classifier
>> Scanning Files
>> Done!

Example

Before:

Downloads
│   ├── project.docx
│   ├── 21 Guns.mp3
│   ├── Sultans of Swing.mp3
│   ├── report.pdf
│   ├── charts.pdf
│   ├── VacationPic.png
│   ├── CKEditor.zip
│   ├── Cats.jpg
│   └── archive.7z

After:

Downloads
│   ├── Music
│   │   ├── 21 Guns.mp3
│   │   └── Sultans of Swing.mp3
|   |
│   ├── Documents
│   │   ├── project.docx
│   │   ├── report.pdf
│   │   └── charts.pdf
|   |
│   ├── Archives
│   │   ├── CKEditor.zip
│   │   └── archive.7z
|   |
│   ├── Pictures
│   │   ├── VacationPic.png
│   │   └── Cats.jpg

Options

classifier [-dt] [-st SPECIFIC_TYPES [SPECIFIC_TYPES ...]] [-sf SPECIFIC_FOLDER] [-o OUTPUT]

optional arguments:

-h --help				show help message and exit

-dt --date				Classify the files by their Creation Date
-st --specific-types			Move the specific file extensions into the Specific Folder
-sf --specific-folder			Folder to move files with Specific Type

-d --directory				The directory whose files you want to classify
-o --output				Main directory to put organized folders

-v --version         			show version
-t --types           			Show the current list of types and formats
-et --edittypes      			Edit the list of types and formats (edit the CONFIG)

-rst					Reset the CONFIG file

Example

Classify specific file types

classifier -st py pyc -sf "Python Files"

Before

Workspace
│   ├── views.py
│   ├── temp.pyc
│   ├── game.java
│   ├── index.html
│   └── script.py

After

Workspace
│   ├── Python Files
│   │   ├── views.py
│   │   ├── temp.pyc
|   |	└── script.py
|   |
|   ├── game.java
|   └── index.html

Example

Classify by Date:

classifier -dt

Example

Classify files of directory '/home/source' and put them in location '/home/dest':

classifier -d /home/source -o /home/dest

Note: If -d (source directory) is given without -o (output) directory, this will classify the files of source directory Eg:
classifier -d /home/source'
This classifies the directory /home/source.

View the CONFIG, how files will be sorted

classifier -t

Edit the CONFIG, to set up manual settings for classification

classifier -et

Reset the CONFIG file

classifier -rst


======

The MIT License

Copyright (c) 2015 Bhrigu Srivastava http://bhrigu123.github.io

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

classifier's People

Contributors

aviaryan avatar bhrigu123 avatar d6o avatar disiqueira avatar draxus avatar drnightmare avatar halflings avatar leokhachatorians avatar mjcortejo avatar moun3imy avatar neui avatar psachin avatar s avatar sqbing avatar steveedson avatar sullivat avatar tanelpuhu avatar yask123 avatar yittg avatar zenofsahil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

classifier's Issues

Lol had the same idea as you guys

I had the same idea here a little while back: Mine but with something similar

I did not know you this existed. But I was having trouble finding where I could make this run in the background of all OS's. But I'd thought I just say thanks for making this! You did more of a better job for what I have accomplished so far in my repository. If there is any issues you need fixing, I will fix it.

Program SHOULD NOT move files! Test mode like in rsync is important

Seems a promising start of a file sorting/classifiying program BUT (ALL is my opinion)

  • the program is immediately moving after start EVEN WITHOUT any parameters given! NEVER DO THIS! An -N like in rsync would be by default very important!
  • PDF Files and Windows Documents should be parsed and maybe by sorted by recipient/author etc.
  • Cannot move file - Vodafone_kw_aenderung.pdf - [Errno 18] Invalid cross-device link
  • Therefore An AI Algorithm would be very great

I have wrote a file sorting/categorizing program by Bash shell script too, but without an huge logic (your program is just 11 KB) behind, it is just simple like find * -type -exec get_fileext_and_move_file.sh "{}" ;
Anyway it seems to be promising start

Undo feature request

It feels like there should be an undo command, in case someone runs classifier in the wrong directory, or even for making testing it out easier. Essentially to avoid the permanence of the classifying, which may be unwanted.

That could be done by keeping a copy of the directory tree before any changes are made, so the undo command puts it all back to place, or actually keeping a copy of the dirnames (folder names) that classifier created, which then the undo command would empty back out to the root folder.

Are there any difficulties in this that I'm missing?

pkg_resources.DistributionNotFound: The 'arrow'

➜ Downloads classifier
Traceback (most recent call last):
File "/usr/bin/classifier", line 6, in
from pkg_resources import load_entry_point
File "/usr/lib/python3.6/site-packages/pkg_resources/init.py", line 3036, in
@_call_aside
File "/usr/lib/python3.6/site-packages/pkg_resources/init.py", line 3020, in _call_aside
f(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/pkg_resources/init.py", line 3049, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/lib/python3.6/site-packages/pkg_resources/init.py", line 654, in _build_master
ws.require(requires)
File "/usr/lib/python3.6/site-packages/pkg_resources/init.py", line 968, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/lib/python3.6/site-packages/pkg_resources/init.py", line 854, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'arrow' distribution was not found and is required by classifier

Getting this exception : ImportError: cannot import name getcwd

I get this exception when trying to run the script on my Downloads folder

Traceback (most recent call last):
File "/usr/local/bin/classifier", line 7, in
from classifier.classifier import main
File "/Library/Python/2.7/site-packages/classifier/classifier.py", line 8, in
from six.moves import getcwd
ImportError: cannot import name getcwd

Classify installers (for downloads folder)

Hi. I ran classifier in my Downloads folder just now and was wondering if there'd be a way to classify installers (normally I'd just delete them but I figured this wouldn't be a bad idea, especially if you're using it on a Downloads folder)

feature request: ical (and spreadsheet?)

Hi!

awesome package, i just came across it on twitter and had organised my downloads in less than a minute - congratulations

I wonder if you could add in a calendar folder - i didnt realise how many .ics files i had in my downloads folder. would be cool if they could be aggregated too.

also seems that excel files didnt get picked up, although admittedly it isn't obvious that these should be collected.

anyway, congratulations on a great piece of code

adam

Inaccuracy in checking file extension.

Sometimes file extensions are not correct w.r.t. what they actually are. Moreover some files are not even provided with any format.

Using something similar to file command in linux would produce better results.
Maybe python-magic can help.

.tar.gz files not being moved

Files of typefile.tar.gz get split likefilename = file.tar and file_ext = .gz and thus don't get moved in specified folders.

Same filename

I encountered problem when I am downloading more files with same name every few days, then classifier cant move it because same filename issue, can you fix this by etc adding parameter to owerwrite file or move it with different name

Tests failing

I always get AttributeError: module 'classifier.classifier' has no attribute 'self' when running tests. Is there something that I am missing?

Issue with archive extensions

os.path.splitext('example.tar.gz')
returns '.gz' as the extension, and not '.tar.gz' as expected.

Same issue applies to tar.bz2 files.

One fix would be to change the extensions in formats from .tar.gz to .gz and .tar.bz2 to .bz2

Crashes if config contains a blank line

Traceback (most recent call last): File "/usr/local/bin/classifier", line 289, in <module> Classifier() File "/usr/local/bin/classifier", line 115, in __init__ self.checkconfig() File "/usr/local/bin/classifier", line 133, in checkconfig val = spl[1].replace(" ","") IndexError: list index out of range
I suggest changing the flow control, maybe wrapping it in a try catch block. This traceback isn't very informative.

Windows Support (Feature Request)

Hey,
I really like the idea of this python module you have there. Why doesn't it support windows for the time being ? I mean what are the restrictions and problems you're facing ?

UnicodeDecodeError raised when the name of candidate (file or directory) is Chinese

I get the UnicodeDecodeError when run classifier in directory including Chinese filenames.

Traceback (most recent call last):
  File ".../bin/classifier", line 11, in <module>
    sys.exit(main())
  File ".../lib/python2.7/site-packages/classifier/classifier.py", line 104, in main
    classify_by_date('DD-MM-YYYY', args.output)
  File ".../lib/python2.7/site-packages/classifier/classifier.py", line 58, in classify_by_date
    moveto(file, directory, folder)
  File ".../lib/python2.7/site-packages/classifier/classifier.py", line 20, in moveto
    to_file = os.path.join(to_folder, file)
  File ".../lib/python2.7/posixpath.py", line 73, in join
    path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 1: ordinal not in range(128)

.ISO extension is missing

There should either be a separate folder (like Image files) for *.ISO files or it can be added into the 'Archives' folder.

Shouldn't create unnecessary directories.

I noticed that even if there are no audio files, it creates a directory 'Music'. This happens for other directories also. Please avoid this. If the file-formats are not found, don't create an empty directory.

does not run

Program does not run on my pc, because of a typo. If you see the following line "'Videos': ['.flv', '.ogv', '.avi', '.mp4', '.mpg', '.mpeg', '.3gp', '.mkv', '.ts', , '.webm', '.vob', '.wmv'],"

you will see that there are two commas before webm.

Excellent project!:)

link farm - (feature req)

Consider leaving the files where they lie, and then create a tree of symbolic links pointing to the files. The advantage here is you can have a number of "views" into the files by adding more trees of links. This lets a file be referred to by a number of views. Eg,

Downloads
│   ├── OriginalFiles
│   ├── ByDate
│   │   └── 2015
│   │   └── 2014
│   ├── ByType
│   │   └──docs
│   │   └──pdfs
│   │   └──zip
│   ├── Bills
│   │   └──Comcast
│   │   └──Verizon
│   ├── CodeProjects
│   │   └──C++
│   │   └──Java

I guess looking into a file and categorizing by keyword is a different classification feature, like you might want to look into a PDF (ocr it?) and depending on predefined keyword list, stick it in Verizon, Date, and Bills trees.

Keeping the link farm synchronized with the real files might get interesting. You might want several policies, the simplest of which is blow away all the links and regenerate after a rule changes.

Create a standalone file of MIT LICENSE

Hello,
I am make a package RPM to install your tool on "Fedora Linux" .
In order to accomplish all requisites, a licence copy is required in single file named: LICENSE

Do you want accept this request?

I will waiting for your answer .

Greetings

[IMPROVEMENT] Add capability to load multiple settings file

I have the idea to add capability to classifier load multiple settings file.
For example, I could create dotnet-developer.settings for dotnet files, then, when I run classifier, it will classify also dotnet files. Something like .gitignore, but for classifier.

[Feature] Specific file types only sorted

I think we should add an option for users to sort specific files/file types/categories into their own folders.

For example: classifier -S *.py *.pyc "Python Files"

This will sort all py and pyc files into a folder named "Python Files" without touching the rest of the files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.