Created
December 5, 2009 23:39
-
-
Save clutchski/249919 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This module demonstrates the functionality | |
of the fileutils library. | |
http://github.com/clutchski/fileutils | |
""" | |
import fileutils | |
# | |
# Let's make some directories. | |
# | |
# You can create directories one at a time. | |
fileutils.mkdir('animals') | |
# Or many at a time, if you want. | |
fileutils.mkdir(['animals/birds', 'animals/reptiles']) | |
# Missing parent directories can be created as well. | |
fileutils.mkdir_p('animals/mammals/ungulates') | |
# Too lazy to check if a directory exists? | |
# Don't worry, like the *nix implementation, | |
# fileutils' mkdir_p is idempotent. | |
fileutils.mkdir_p('animals/mammals/ungulates') | |
# | |
# Let's mess around with some files. | |
# | |
# Let's create some. | |
fileutils.touch('animals/birds/loon') | |
fileutils.touch( | |
['animals/reptiles/turtle', 'animals/reptiles/elk']) | |
fileutils.touch('animals/mammals/baaji_river_dolphin') | |
# Whoops, an elk isn't a reptile. | |
# Let's move that where it belongs. | |
fileutils.mv('animals/reptiles/elk', 'animals/mammals/ungulates') | |
# It's too sad to think about extinct animals, so | |
# let's pretend they never existed. | |
fileutils.rm('animals/mammals/baaji_river_dolphin') | |
# 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. | |
# | |
fileutils.rm_rf('animals') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment