Link to home
Start Free TrialLog in
Avatar of chipped
chippedFlag for Australia

asked on

Need to make this script work in OS X and Linux

Hey guys,

I would like to make this Python script compatible with OS X and Linux. If I lauch the script on OS X.
import os
import sys

#path to file from the first argument (no checking)
fname = sys.argv[1]
#fname = r'E:\\TV Shows\\How I Met Your Mother\\Season 6\\How.I.Met.Your.Mother.S06E18.720p.HDTV.X264-DIMENSION.mkv'
print fname

# Now split the path to the directory and the bare name (better to say it 
# splits the last element of the path and it does not care whether it is 
# a file name or a subdirectory name.
path, barename = os.path.split(fname)
print path
print barename

parent = os.path.normpath(os.path.join(path, '..'))
print "parent directory:", parent

# Create file, delete and recreate it if it exists. This will
# change the date modified status of the Show Name folder
# so you can view your show list by date order.
logname = os.path.join(parent, 'DateMarker.log')
if os.path.isfile(logname):
    os.remove(logname)
logfile = open(logname, 'w')
logfile.write('Episode ' + fname + ' has been created. This is a marker file, to change the date modified status of the show name.')
logfile.close()

Open in new window

Everything works except this part
if os.path.isfile(logname):
    os.remove(logname)
logfile = open(logname, 'w')
logfile.write('Episode ' + fname + ' has been created. This is a marker file, to change the date modified status of the show name.')
logfile.close()

Open in new window


Thanks
ASKER CERTIFIED SOLUTION
Avatar of clockwatcher
clockwatcher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chipped

ASKER

Hmmmm, I'll double check.
Avatar of pepr
pepr

How exactly does it fail?
(Sorry, clockwatcher already asked... ;)
Avatar of chipped

ASKER

Doh! It was just permissions.