Source

fsquass / README.rst

FsQuass, file system querying library

Much more info on Read the Docs.

About

This library is a syntactic sugar of os.path and fnmatch, and can do smart searches of files, using such techniques as

  • space-separated ancestor & descendant like in CSS, /home fsquass/fsquass
  • bash-like subpatterns, /{home,tmp}/user
  • CSS-like pseudo-classes, :file, :dir, :ignorecase

Usage

Command line interface:

$ fsquass ". *.py"
/home/siberiano/Work/fsquass/fsquass/tests.py
/home/siberiano/Work/fsquass/fsquass/__init__.py
/home/siberiano/Work/fsquass/fsquass/version.py
/home/siberiano/Work/fsquass/setup.py
/home/siberiano/Work/fsquass/docs/source/conf.py

$ fsquass "/home/*/.bashrc"
/home/siberiano/.bashrc

This is similar to unix find. What new does FsQuass offer? Here are cool things hard to do with find: find all folders that are legitimate Pytohn packages, i.e. have a __init__.py in them:

$ fsquass ". *:dir/__init__.py/.."

Now if I want to do something with them, I use xargs. I can list those directories:

$ fsquass ". *:dir/__init__.py/.." | xargs ls

Or copy them:

$ fsquass ". *:dir/__init__.py/.." | xargs -I '{}' cp -R {} /tmp

You can import fsquass and use it in Python:

from fsquass import Fs
repair_photos = Fs('~/Pictures/{2010,2011}/*repair *.jp?g:ignorecase:file')

packages_with_setup = Fs('. setup.py').parents()
# and so on

Installation

Install the package with setup.py or with your python package manager:

python setup.py install