Erik van Blokland 3646055ea2 initial import
git-svn-id: http://svn.robofab.com/trunk@1 b5fa9d6c-a76f-4ffd-b3cb-f825fc41095c
2008-01-07 17:40:34 +00:00

43 lines
1.2 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# robothon06
# ask for a folder
# find (nested) fontlab files in the folder
# open the fonts
# Demonstrates: recursive function,, dialog, os module
import os.path
from robofab.interface.all.dialogs import GetFolder
from robofab.world import OpenFont
# this function looks for fontlab files in a folder
def walk(someFolder, extension):
extension = extension.lower()
files = []
# the os module has tools to deal with
# the operating system. This returns a list of names
# of stuff in the folder you feed it:
names = os.listdir(someFolder)
for n in names:
p = os.path.join(someFolder, n)
# if this new thing is a folder itself,
# call this function again, but now with the
# new path to check that as well. This is
# called recursion.
if os.path.isdir(p):
# add the results of the other folder
# to the list
files += walk(p, extension)
continue
# is it a file with the extension we want?
# add it then!
if n.lower().find(extension) <> -1:
files.append(p)
return files
yourFolder = GetFolder("Search a folder:")
if yourFolder is not None:
fontPaths = walk(yourFolder, ".vfb")
for path in fontPaths:
OpenFont(path)