#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    38
    Rep Power
    5

    Dos commands and python program


    hi
    i'd like to make my steps in my project in python program
    but i do not know some commands to do that
    such as copy file from somewhere to another
    or make folder , ....
    also how i can run command in dos by using python program

    for example:
    if i want to run dir command in dos by using python.
    how i can do that?

    any ideas?
    or
    some example or codes to try?

    thank you
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    610
    Rep Power
    65
    The Python module os is your friend.
    Read the Python manual for all the things it can do!

    To answer your last question, this will run the DOS command DIR for you:
    [code=python]import os

    # for Windows OS
    os.system("DIR")

    # optional console wait (Python2)
    raw_input("press enter to go on ... ")
    [/code]
    Last edited by Dietrich; July 1st, 2010 at 12:01 PM.
    Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2009
    Posts
    383
    Rep Power
    0
    The os module is indeed you friend... but not because it has .system() but because it abstracts platform-specific commands away (as far as possible, e.g. windows just doesn't have the rich set of process id-related functions). For example, os.chdir is the cross-platform dir, etc. The os.file module and the shutil module are useful for file system interaction, too.
    Last edited by delnan; July 1st, 2010 at 11:46 AM.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    38
    Rep Power
    5
    thanx

IMN logo majestic logo threadwatch logo seochat tools logo