Adding PC Filename Extensions to Macintosh Filenames
hokiegal99
hokiegal99 at vt.edu
Tue Aug 5 22:45:25 EDT 2003
I've written a small script (with much help from this list) that
searches through a directory for files without a PC filename extension
like .doc .xls and then adds them. The reason for writing the script is
that I'm migrating several dozen Mac users to PCs over the next few
months and many of the Mac files do not have PC filename extensions.
There are thousands of these files. The script runs on a Linux ftp
server where the files are upload to.
In testing, the script works OK. It needs work, for example I need to
make certain that the strings I'm searching for to identify file types
are correct. This would be easier if I could assign more than one string
to string.find. I'm considering doing this:
setpath = raw_input("Enter the path: ")
for root, dirs, files in os.walk(setpath):
old_fname = files
for old_fname in files:
new_fname = old_fname + '.xls'
exclude = string.find(old_fname,'.xls')
x = string.find(old_fname,'Excel.Sheet.')
y = string.find(old_fname,'Microsoft Excel')
z = string.find(old_fname,'Worksheet')
p = x, y, z
if p >= 1 and exclude == -1:
newpath = os.path.join(root,new_fname1)
oldpath = os.path.join(root,old_fname)
os.rename(oldpath,newpath)
print oldpath
print newpath
The script as it exists now is attached to this email. Please critique
it and let me know how I can make it better or more accurate. All advice
is welcome both positive and negative. I'd especially like to hear for
people who could show me how I might make the script smaller and more
efficent and ways in which I might ID file types more accurately.
Thanks!!!
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: extensions-0.3.py
URL: <http://mail.python.org/pipermail/python-list/attachments/20030805/a78ed0ab/attachment.ksh>
More information about the Python-list
mailing list