Pylito.py

#!/usr/bin/python

# Stupid little tool for extracting files from a hierarchy of folders
#
# Copyright 2007 Brandon Stafford
#
# Pylito is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Pylito is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Pylito. If not, see .

import os
import shutil

def CollectFiles(source, dest):
dirList = []
fdList = os.listdir(source)

for elem in fdList:
nextFile = os.path.join(source, elem)
if os.path.isdir(nextFile):
print “\nFound directory: “, nextFile
dirList.append(nextFile)
else:
print “Copying “, nextFile, ” to “, dest
error = shutil.copyfile(nextFile, os.path.join(dest, elem))
if os.path.isfile(os.path.join(dest, elem)):
print “Success”
else:
print error
print “\ndirList: “, dirList
for dir in dirList:
CollectFiles(dir, dest)

def ExtractFiles(dir):
home = os.path.expanduser(”~”)
source = os.path.join(home, “Desktop”, “pylito”, dir)
dest = os.path.join(home, “Desktop”, “pylito”, “files”)
if (not os.path.isdir(dest)):
os.mkdir(dest)
CollectFiles(source, dest)

if __name__ == “__main__”:
ExtractFiles(”test”)