aboutsummaryrefslogtreecommitdiff
path: root/scripts/pt.py
blob: e40cac0e45e1fceff19e52cc8091a012ebff105f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# PixelTANGO Python code for dirlist and stripExtension
# Copyright Ben Bogart, Franz Hildgen, 
# The Societe des arts technologiques and
# The Interaccess Electronic Media Arts Centre

import os 
import os.path
import glob

print "pt: py scripts init"

# Removes extension
def stripExtension(arg):
	return os.path.splitext(str(arg))[0]

# Lists files matching pattern in path.
def dirlist(*args):
	if len(args) == 2:
		pattern=str(args[0])
		path=str(args[1])
		files=list('') # Seems like a bad way to create a list var

		test=os.path.join(path,pattern)
		entries=glob.glob(test)

		for entry in entries:
			if os.path.isfile(entry):
				files.append(entry)
		return files
	else:
		print "pt: dirlist only accepts two arguments: [pattern] [path]"
		print "args: ",args

# Removed path component to leave only the filename. 
def stripPath(arg):
	return os.path.basename(str(arg))