All Projects → chriscz → pysorter

chriscz / pysorter

Licence: MPL-2.0 license
A command line utility for organizing files and directories according to regex patterns.

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to pysorter

devfuria.com.br
http://devfuria.com.br/
Stars: ✭ 3 (-92.5%)
Mutual labels:  regex
Gridify
Easy and optimized way to apply Filtering, Sorting, and Pagination using text-based data.
Stars: ✭ 372 (+830%)
Mutual labels:  sorting
spring-boot-jpa-rest-demo-filter-paging-sorting
Spring Boot Data JPA with Filter, Pagination and Sorting
Stars: ✭ 70 (+75%)
Mutual labels:  sorting
expressive-ts
A functional programming library designed to simplify building complex regular expressions
Stars: ✭ 78 (+95%)
Mutual labels:  regex
dora
Find exposed API keys based on RegEx and get exploitation methods for some of keys that are found
Stars: ✭ 229 (+472.5%)
Mutual labels:  regex
fu
Unix's Find, Unleashed.
Stars: ✭ 32 (-20%)
Mutual labels:  regex
bhedak
A replacement of "qsreplace", accepts URLs as standard input, replaces all query string values with user-supplied values and stdout.
Stars: ✭ 77 (+92.5%)
Mutual labels:  regex
ultra-sort
DSL for SIMD Sorting on AVX2 & AVX512
Stars: ✭ 29 (-27.5%)
Mutual labels:  sorting
svelte-datagrid
Svelte data grid spreadsheet best best features and performance from excel
Stars: ✭ 48 (+20%)
Mutual labels:  sorting
sortboard
A small ES6 library for easy sorting and filtering of elements.
Stars: ✭ 29 (-27.5%)
Mutual labels:  regex
tokenquery
TokenQuery (regular expressions over tokens)
Stars: ✭ 28 (-30%)
Mutual labels:  regex
eliza-rs
A rust implementation of ELIZA - a natural language processing program developed by Joseph Weizenbaum in 1966.
Stars: ✭ 48 (+20%)
Mutual labels:  regex
dregex
Dregex is a JVM library that implements a regular expression engine using deterministic finite automata (DFA). It supports some Perl-style features and yet retains linear matching time, and also offers set operations.
Stars: ✭ 37 (-7.5%)
Mutual labels:  regex
LLRegex
Regular expression library in Swift, wrapping NSRegularExpression.
Stars: ✭ 18 (-55%)
Mutual labels:  regex
regextester
An elementary OS app
Stars: ✭ 38 (-5%)
Mutual labels:  regex
solregex
Regex compilation to Solidity
Stars: ✭ 37 (-7.5%)
Mutual labels:  regex
CVparser
CVparser is software for parsing or extracting data out of CV/resumes.
Stars: ✭ 28 (-30%)
Mutual labels:  regex
RideShare-Trip-Stats
Chrome Extension to visualize your uber trip statistics
Stars: ✭ 61 (+52.5%)
Mutual labels:  regex
cakephp-sequence
CakePHP plugin for maintaining a contiguous sequence of records
Stars: ✭ 41 (+2.5%)
Mutual labels:  sorting
algos
A collection of algorithms in rust
Stars: ✭ 16 (-60%)
Mutual labels:  sorting

GitHub version PyPI version Build Status Coverage Status

Pysorter

A Commandline utility for organizing files and directories according to regex patterns.

Quick Start

  • pip install pysorter
  • pysorter

Commandline Synopsys

usage: pysorter [-h] [-d DEST_DIR] [-p] [-t FILETYPES] [-u UNHANDLED_FILE]
                [-r] [-c] [-n] [-V]
                directory

Reorganizes files and directories according to certain rules

positional arguments:
  directory             The directory to be organized

optional arguments:
  -h, --help            show this help message and exit
  -d DEST_DIR, --destination DEST_DIR
                        The destination directory to move organized files to.
  -p, --process-dirs    Should directories also be matched against the rules?
  -t FILETYPES, --filetypes FILETYPES
                        File containing regex rules [Default: filetypes.py]
  -u UNHANDLED_FILE, --unhandled-file UNHANDLED_FILE
                        Write the paths of all unhandled items to this file
  -r, --recursive       Recursively organize directories
  -c, --remove-empty-dirs
                        Recursively removes all empty directories in the
                        directory being organized.
  -n, --dry-run         Prints out the changes that would occur, without
                        actually executing them.
  -V, --version         Prints out the current version of pysorter

Configuration

Pysorter ships with a default rules file that has entries for many common file types. As a user of pysorter, you are encouraged to add your own rules using pysorter/filetypes.py file for inspiration.

Example 1

Suppose we would like all our pdfs to be placed under a pdf directory, located under /home/chris/sorted/documents/. As a first step we must write a rules file. This file is a normal Python module that defines where certain files will be moved to.

    RULES = [
        # regex pattern, destination
        (r'.*\.pdf$', 'documents/pdf/' ),
    ]

Notes

  • Rules are attempted in the order they are defined. As soon as a match is found, we use its destination.
  • The slash in the destination (documents/pdf/) is important, as all pdfs will be placed in the documents/pdf/ directory. If the slash was removed as in document/pdf, then all pdfs would be moved to a file named pdf in the directory document. Which is definitely not what you wanted!
  • The destination could also be a Python that will be called during processing.

Example 2

We would like all images downloaded from facebook to be located under images/facebook/ instead of putting them directly inside images/. You'll notice that facebook images end in _n.jpg. We would like to strip away that prefix as well. So we write the following rule,

    RULES = [
        # ... some other rules ...
        (r'(?P<filename>[^/]+)_n.jpe?g$', 'images/facebook/{filename}.jpg')
        # ... yet some more rules ...
    ]

Notes

This example might look complicated, but it is really just using standard Python functionality. To break it down.

  • (?P<filename>[^/]+) is a named capturing group, it matches any character that is not a /, therefore the filename without extension. Here are some example matches

    • tosort/myphoto_n.jpg. filename=myphoto
    • tosort/foo/y123_n.jpg. filename=y123
  • In the destination of the rule we can make use of both named and unnamed capturing groups.

You can look at the pysorter.filetypes module for some more inspiration.

Caveats

The Python shutil library used by pysorter carries the following warning:

Warning 
Even the higher-level file copying functions (shutil.copy(), shutil.copy2()) cannot copy all file metadata.

- On POSIX platforms, this means that file owner and group are lost as well as ACLs. 
- On Mac OS, the resource fork and other metadata are not used. 
  This means that resources will be lost and file type and 
  creator codes will not be correct. 
- On Windows, file owners, ACLs and alternate data streams are not copied.

If the files are on the same filesystem, then neither copy nor copy2 are actually used, so there shouldn't be any risks involved.

If you still feel unsure, feel free to create an issue, and we'll try our best to help.

Requirements

Python version:

  • 2.7
  • 3.3
  • 3.4
  • 3.5

Contributing

See the guide.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].