Announcing fileutils, a UNIX inspired file system library

. clutchski clutchski at
Sun Dec 6 01:55:01 CET 2009


I am happy to announce the release of
a file system library inspired by classic UNIX programs like cp, mkdir and
chmod. It is an attempt to smooth out some of the rough edges in the
standard library's os and shutil modules, and create an intuitive,
convenient way of working with files.

Ok, I am going to stop blathering and let the code speak for itself. Here's
a dummy example that demonstrates what fileutils can do (click
here<>for syntax highlighting).

This module demonstrates the functionality
of the fileutils library.

import fileutils

# Let's make some directories.

# You can create directories one at a time.

# Or many at a time, if you want.
fileutils.mkdir(['animals/birds', 'animals/reptiles'])

# Missing parent directories can be created as well.

# Too lazy to check if a directory exists?
# Don't worry, like the *nix implementation,
# fileutils' mkdir_p is idempotent.

# Let's mess around with some files.

# Let's create some.
    ['animals/reptiles/turtle', 'animals/reptiles/elk'])

# Whoops, an elk isn't a reptile.
# Let's move that where it belongs.'animals/reptiles/elk', 'animals/mammals/ungulates')

# It's too sad to think about extinct animals, so
# let's pretend they never existed.

# Want anyone to be able to execute your elk?
# Well, go ahead and change the permissions.
fileutils.chmod('0755', 'animals/mammals/ungulates/elk')

# Let's change the ownership of some files.
fileutils.chown('apache', 'apache', 'animals/reptiles/turtle')
fileutils.chown_R('apache', 'apache', 'animals/mammals')

# Let's clean up and head home.


That's it! It's on PyPi, so you can install with "sudo easy_install
fileutils". Check out the source code
And here<>is
a blog post detailing the library's motivation and inspiration. And as
always, if anyone has any suggestions, thoughts or comments, it'd be great
to hear from you.

Thanks and take care,

More information about the Python-announce-list mailing list