File: fixfiletypes.py

package info (click to toggle)
python2.3 2.3.5-3sarge2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 43,908 kB
  • ctags: 81,384
  • sloc: ansic: 266,250; python: 246,028; makefile: 4,194; perl: 3,702; lisp: 3,630; sh: 2,576; xml: 1,601; objc: 740; cpp: 106; sed: 2
file content (56 lines) | stat: -rw-r--r-- 1,261 bytes parent folder | download
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#
# Fixfiletypes - Set mac filetypes to something sensible,
#  recursively down a directory tree.
#
# It will only touch extensions it feels pretty sure about.
# This script is useful after copying files from unix.
#
# Jack Jansen, CWI, 1995.
#
import os
import EasyDialogs
import sys
import macostools
import MacOS

list = [
	('.py', 'Pyth', 'TEXT'),
	('.pyc', 'Pyth', 'PYC '),
	('.c', 'CWIE', 'TEXT'),
	('.h', 'CWIE', 'TEXT'),
	('.as', 'ToyS', 'TEXT'),
	('.hqx', 'BnHq', 'TEXT'),
	('.cmif', 'CMIF', 'TEXT'),
	('.cmc', 'CMIF', 'CMC '),
	('.aiff', 'SCPL', 'AIFF'),
	('.mpg', 'mMPG', 'MPEG'),
]

def walktree(name, change):
	if os.path.isfile(name):
		for ext, cr, tp in list:
			if name[-len(ext):] == ext:
				curcrtp = MacOS.GetCreatorAndType(name)
				if curcrtp <> (cr, tp):
					if change:
						MacOS.SetCreatorAndType(name, cr, tp)
						#macostools.touched(fs)
						print 'Fixed ', name
					else:
						print 'Wrong', curcrtp, name
	elif os.path.isdir(name):
		print '->', name
		files = os.listdir(name)
		for f in files:
			walktree(os.path.join(name, f), change)
			
def run(change):
	pathname = EasyDialogs.AskFolder(message='Folder to search:')
	if not pathname:
		sys.exit(0)
	walktree(pathname, change)
	
if __name__ == '__main__':
	run(1)