FsQuass, filesystem query and traversing

Why another filesystem library?

None of them lets you work with files and paths in an elegant way. By elegant I mean as jQuery lets you work with DOM. A jQuery for filesystem is not a new idea, though: someone has written fsquery library for Node.js. There is a good pyFileSystem library that supports different file systems (like ssh, memory, ftp).

I rather needed a path traversing tool than filesystem.

Let’s say, I want to find photos (*.jp[e]g) in my pictures folders for 2010 and 2011. The folders for those days end with 'repairs'.

from fsquass import Fs
photos = Fs('/home/siberiano/Pictures/{2011,2010} *repairs *.jp?g:ignorecase')

Note how syntax is similar to what we’re used to in file systems:

  • spaces in path stand for descendant, like in CSS
  • curly braces {x,y} mean different masks of a name
  • stars and question marks work like in command line
  • pseudo-classes (:ignorecase) work like in CSS

Now I can proceed, say, find the folders of these files:

photos.parents().find('*.txt')
photos.filter('DCIM*')

As you can see, it’s quite similar to jQuery. But unlike jQuery, Python’s set classes support set operations:

photos.parents().children() - photos

Everything you can do with set, you can do with Fs objects as well.

Installation

Clone it and install with setuptools:

hg clone https://bitbucket.org/siberiano/fsquass
cd fsquass
python setup.py install

What does the name mean?

It’s called so to give it a unique name and flavour. ‘Quass’ has common part with ‘query’, but means kvass.

Indices and tables

Project Versions

Table Of Contents

Next topic

Quick Tour

This Page