Solved

Need to make this script work in OS X and Linux

Posted on 2011-03-05
5
417 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:chipped
  • 2
  • 2
5 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
ID: 35043004
It seems to work fine for me in linux.   Assuming you have write permissions to the parent directory and permissions to remove DateMarker.log if it exists, I don't see anything obvious in it that would lead me to believe it wouldn't work on a Mac.  What output and error are you getting?  
0
 

Author Comment

by:chipped
ID: 35043023
Hmmmm, I'll double check.
0
 
LVL 28

Expert Comment

by:pepr
ID: 35044483
How exactly does it fail?
0
 
LVL 28

Expert Comment

by:pepr
ID: 35044485
(Sorry, clockwatcher already asked... ;)
0
 

Author Comment

by:chipped
ID: 35045910
Doh! It was just permissions.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Make a file test.vbs using vbscript 5 63
Control Number of Log Files -Perl 7 54
how to pick specific file from ftp 13 39
File Sharing with Apple and Windows 7 40
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now