chdir()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • HMS Surprise

    #1

    chdir()


    Tried executing os.chdir("c:\tw ill") 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

  • Jarek Zgoda

    #2
    Re: chdir()

    HMS Surprise napisa³(a):
    Tried executing os.chdir("c:\tw ill") 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

    Comment

    • Basilisk96

      #3
      Re: chdir()

      On May 8, 3:54 pm, HMS Surprise <j...@datavoice int.comwrote:
      Tried executing os.chdir("c:\tw ill") 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:\t will")
      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

      Comment

      • Necmettin Begiter

        #4
        Re: chdir()

        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

        Comment

        • Carsten Haese

          #5
          Re: chdir()

          On Tue, 2007-05-08 at 12:54 -0700, HMS Surprise wrote:
          Tried executing os.chdir("c:\tw ill") 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:\\t will")
          os.chdir(r"c:\t will")

          HTH,

          --
          Carsten Haese



          Comment

          • HMS Surprise

            #6
            Re: chdir()

            On May 8, 3:06 pm, Carsten Haese <cars...@uniqsy s.comwrote:
            On Tue, 2007-05-08 at 12:54 -0700, HMS Surprise wrote:
            Tried executing os.chdir("c:\tw ill") 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:\\t will")
            os.chdir(r"c:\t will")
            >
            HTH,
            >
            --
            Carsten Haesehttp://informixdb.sour ceforge.net
            Thanks all. Windows bytes me again. I know better just wasn't
            thinking. \n

            Comment

            Working...