Windows commands

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gloomer
    New Member
    • Apr 2007
    • 13

    #1

    Windows commands

    Hey guys, i'm back.

    Code:
    import os
    os.system("mkdir c:\test")

    Why doesn't this work? It should work. But it doesn't. How can I use commands in windows through the os.system module.

    This is a module right? Or a library. I don't know.
  • gloomer
    New Member
    • Apr 2007
    • 13

    #2
    Ok this is officially messed up.

    My python .py script is in the My Documents folder.

    I execute it, and oh no, it does not create the folder "test" in C:\

    It creates the folder "est" in My Documents.

    How does it make "est" out of test!!!!??

    I did not miss spell it. Seriously. What i'm I doing wrong?

    Comment

    • theJade
      New Member
      • Apr 2007
      • 5

      #3
      \ is escaping the next character t so \t is replaced with a tab character. The command you're really sending it is 'mkdir c: <tab> est'. The chacter for '\' is actually '\\' so try the following.

      import os
      os.system("mkdi r c:\\test")

      Comment

      • gloomer
        New Member
        • Apr 2007
        • 13

        #4
        Ahhhh. Now I get it. Thanks a ton.

        Comment

        • ghostdog74
          Recognized Expert Contributor
          • Apr 2006
          • 511

          #5
          Originally posted by gloomer
          Hey guys, i'm back.

          Code:
          import os
          os.system("mkdir c:\test")

          Why doesn't this work? It should work. But it doesn't. How can I use commands in windows through the os.system module.

          This is a module right? Or a library. I don't know.
          An advice, try not to use the system's mkdir to do this particular task of making a directory. The os module comes with the mkdir() method for this purpose
          Code:
          import os
          yourdir = os.path.join("c:\\","test")
          os.mkdir(yourdir)
          this will make your code more independent of the platform you run your script.

          Comment

          Working...