Re: problems with opening files due to file's path



On Jun 10, 11:45 am, Alexnb <alexnbr...@xxxxxxxxx> wrote:
Gerhard Häring wrote:

Alexnb wrote:
Okay, so what I want my program to do it open a file, a music file in
specific, and for this we will say it is an .mp3. Well, I am using the
system() command from the os class. [...]

system("\"C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Weezer\(2001)\04 - Island In The Sun.wma\"")
[...]

Try os.startfile() instead. It should work better.

-- Gerhard

--
http://mail.python.org/mailman/listinfo/python-list

No, it didn't work, but it gave me some interesting feedback when I ran it
in the shell. Heres what it told me:

os.startfile("C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm
Yours.wma")

Traceback (most recent call last):
  File "<pyshell#10>", line 1, in <module>
    os.startfile("C:\Documents and Settings\Alex\My Documents\My
Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm Yours.wma")

WindowsError: [Error 2] The system cannot find the file specified:
"C:\\Documents and Settings\\Alex\\My Documents\\My
Music\\Rhapsody\\Bryanbros\\Jason Mraz\\I'm Yours (Single)\x01 - I'm
Yours.wma"

See it made each backslash into two, and the one by the parenthesis and the
0 turned into an x....
--
View this message in context:http://www.nabble.com/problems-with-opening-files-due-to-file%27s-pat...
Sent from the Python - python-list mailing list archive at Nabble.com.

Yeah. You need to either double all the backslashes or make it a raw
string by adding an "r" to the beginning, like so:

os.startfile(r'C:\path\to\my\file')

HTH

Mike
.



Relevant Pages

  • Re: problems with opening files due to files path
    ... Alexnb wrote: ... and for this we will say it is an .mp3. ... systemcommand from the os class. ...
    (comp.lang.python)
  • Re: insert new line in files
    ... .subdir2 etc. ... I've done stuff like this before with the rpl script and it works well ... I don't see a backslash in the error message, ... Are you running this command from something other than the commandline or a ...
    (freebsd-questions)
  • AW: rmake error
    ... There are two particularly mean errors in rmake files: ... This means that a blank line before the linker command might lead to a life sentence or even heavier penalties. ... Blanks after a backslash at the end of the line are threatened with a court-martial and getting shot with cat droppings! ... clipper one ...
    (comp.lang.clipper)
  • Re: Remote Shutdown using Java
    ... two backslashes in the executed command line? ... The Java compiler generates one "delivered" ... backslash for each pair in the source, ... the shell makes one backslash out of each pair that *it* ...
    (comp.lang.java.programmer)
  • Re: FILE pointer
    ... pointer returns NULL at the very beginning eventhough the file is ... and I shift back to the one without command line arguments ... the problem is you forgot that, in order to include a backslash in a ...
    (comp.lang.c)