[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Need to make this script work in OS X and Linux

Posted on 2011-03-05
5
Medium Priority
?
424 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 2000 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 29

Expert Comment

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article we will discuss some EI Capitan Mail app issues and provide some manual process to resolve them.
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.
The viewer will learn how to dynamically set the form action using jQuery.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

649 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