1995-08-09 12:16:58 -03:00
|
|
|
#
|
|
|
|
# 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
|
2003-01-26 17:40:00 -04:00
|
|
|
import EasyDialogs
|
1995-08-09 12:16:58 -03:00
|
|
|
import sys
|
1996-09-15 19:13:59 -03:00
|
|
|
import macostools
|
2003-02-06 19:13:11 -04:00
|
|
|
import MacOS
|
1995-08-09 12:16:58 -03:00
|
|
|
|
|
|
|
list = [
|
1996-02-21 11:36:26 -04:00
|
|
|
('.py', 'Pyth', 'TEXT'),
|
|
|
|
('.pyc', 'Pyth', 'PYC '),
|
1995-10-09 20:18:21 -03:00
|
|
|
('.c', 'CWIE', 'TEXT'),
|
|
|
|
('.h', 'CWIE', 'TEXT'),
|
|
|
|
('.as', 'ToyS', 'TEXT'),
|
1996-02-21 11:36:26 -04:00
|
|
|
('.hqx', 'BnHq', 'TEXT'),
|
|
|
|
('.cmif', 'CMIF', 'TEXT'),
|
1996-03-18 09:33:15 -04:00
|
|
|
('.cmc', 'CMIF', 'CMC '),
|
|
|
|
('.aiff', 'SCPL', 'AIFF'),
|
|
|
|
('.mpg', 'mMPG', 'MPEG'),
|
1995-08-09 12:16:58 -03:00
|
|
|
]
|
|
|
|
|
|
|
|
def walktree(name, change):
|
|
|
|
if os.path.isfile(name):
|
|
|
|
for ext, cr, tp in list:
|
|
|
|
if name[-len(ext):] == ext:
|
2003-02-06 19:13:11 -04:00
|
|
|
curcrtp = MacOS.GetCreatorAndType(name)
|
1995-08-09 12:16:58 -03:00
|
|
|
if curcrtp <> (cr, tp):
|
|
|
|
if change:
|
2003-02-06 19:13:11 -04:00
|
|
|
MacOS.SetCreatorAndType(name, cr, tp)
|
1996-09-15 19:13:59 -03:00
|
|
|
macostools.touched(fs)
|
1995-08-09 12:16:58 -03:00
|
|
|
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):
|
2003-01-26 17:40:00 -04:00
|
|
|
pathname = EasyDialogs.AskFolder(message='Folder to search:')
|
|
|
|
if not pathname:
|
1995-08-09 12:16:58 -03:00
|
|
|
sys.exit(0)
|
2003-01-26 17:40:00 -04:00
|
|
|
walktree(pathname, change)
|
1995-08-09 12:16:58 -03:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2003-02-06 19:13:11 -04:00
|
|
|
run(0)
|
1995-08-09 12:16:58 -03:00
|
|
|
|
|
|
|
|