chdir()

Discussion in 'Python' started by HMS Surprise, May 8, 2007.

  1. HMS Surprise

    HMS Surprise Guest

    Tried executing os.chdir("c:\twill") from a python Tk shell and got
    the error message:

    WindowsError: [Error 123] The filename, directory name, or volume
    label syntax is incorrect: 'c:\twill'.

    I have the directory exists as I copied the name from the explorer
    window that was open to it.

    What is wrong with the syntax?

    thanks,

    jh
     
    HMS Surprise, May 8, 2007
    #1
    1. Advertising

  2. HMS Surprise

    Jarek Zgoda Guest

    HMS Surprise napisa³(a):
    > Tried executing os.chdir("c:\twill") from a python Tk shell and got
    > the error message:
    >
    > WindowsError: [Error 123] The filename, directory name, or volume
    > label syntax is incorrect: 'c:\twill'.
    >
    > I have the directory exists as I copied the name from the explorer
    > window that was open to it.
    >
    > What is wrong with the syntax?


    Unescaped '\' character. Try with raw string (r"c:\twill") or escape it
    ("c:\\twill").

    --
    Jarek Zgoda
    http://jpa.berlios.de/
     
    Jarek Zgoda, May 8, 2007
    #2
    1. Advertising

  3. HMS Surprise

    Basilisk96 Guest

    On May 8, 3:54 pm, HMS Surprise <> wrote:
    > Tried executing os.chdir("c:\twill") from a python Tk shell and got
    > the error message:
    >
    > WindowsError: [Error 123] The filename, directory name, or volume
    > label syntax is incorrect: 'c:\twill'.
    >
    > I have the directory exists as I copied the name from the explorer
    > window that was open to it.
    >
    > What is wrong with the syntax?
    >
    > thanks,
    >
    > jh



    Use
    os.chdir(r"c:\twill")
    instead.

    The "\t" character is the escape character for a tab. You can avoid
    such a faux pas by using the raw string construct of the form r"some
    string". Otherwise, any backslashes in in your string will be
    interpreted as escape characters.

    -Basilisk96
     
    Basilisk96, May 8, 2007
    #3
  4. On Tuesday 08 May 2007 22:54:39 HMS Surprise wrote:
    > WindowsError: [Error 123] The filename, directory name, or volume
    > label syntax is incorrect: 'c:\twill'.
    >
    > What is wrong with the syntax?


    Try 'c:\\twill' because the '\' character is the escape character.
    Eg: \n is new-line (aka crlf)
    \t is tab etc.

    To understand how these work, try this:

    print 'hello\nworld'

    and you get:

    hello
    world
     
    Necmettin Begiter, May 8, 2007
    #4
  5. On Tue, 2007-05-08 at 12:54 -0700, HMS Surprise wrote:
    > Tried executing os.chdir("c:\twill") from a python Tk shell and got
    > the error message:
    >
    > WindowsError: [Error 123] The filename, directory name, or volume
    > label syntax is incorrect: 'c:\twill'.


    Backslash-t is a tab character, so you're trying to chdir to
    C:<tab>will, which is not a valid path name. Use a forward slash, double
    up the backslash, or use a raw string literal:

    os.chdir("c:/twill")
    os.chdir("c:\\twill")
    os.chdir(r"c:\twill")

    HTH,

    --
    Carsten Haese
    http://informixdb.sourceforge.net
     
    Carsten Haese, May 8, 2007
    #5
  6. HMS Surprise

    HMS Surprise Guest

    On May 8, 3:06 pm, Carsten Haese <> wrote:
    > On Tue, 2007-05-08 at 12:54 -0700, HMS Surprise wrote:
    > > Tried executing os.chdir("c:\twill") from a python Tk shell and got
    > > the error message:

    >
    > > WindowsError: [Error 123] The filename, directory name, or volume
    > > label syntax is incorrect: 'c:\twill'.

    >
    > Backslash-t is a tab character, so you're trying to chdir to
    > C:<tab>will, which is not a valid path name. Use a forward slash, double
    > up the backslash, or use a raw string literal:
    >
    > os.chdir("c:/twill")
    > os.chdir("c:\\twill")
    > os.chdir(r"c:\twill")
    >
    > HTH,
    >
    > --
    > Carsten Haesehttp://informixdb.sourceforge.net


    Thanks all. Windows bytes me again. I know better just wasn't
    thinking. \n
     
    HMS Surprise, May 8, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Schull

    cgi-tb after os.chdir

    Jon Schull, Jul 14, 2003, in forum: Python
    Replies:
    0
    Views:
    418
    Jon Schull
    Jul 14, 2003
  2. Yun Mao

    os.environ and os.path.chdir

    Yun Mao, Sep 20, 2003, in forum: Python
    Replies:
    4
    Views:
    444
    Thomas Bellman
    Sep 20, 2003
  3. Tom McDavid
    Replies:
    0
    Views:
    490
    Tom McDavid
    May 13, 2004
  4. Philippe C. Martin

    os.chdir + GUI question

    Philippe C. Martin, Dec 3, 2005, in forum: Python
    Replies:
    0
    Views:
    312
    Philippe C. Martin
    Dec 3, 2005
  5. Replies:
    3
    Views:
    609
    DataSmash
    Jun 2, 2006
Loading...

Share This Page