How to get files of a Directory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cpiyush
    New Member
    • Jan 2007
    • 31

    How to get files of a Directory

    Hi.

    I am trying to read all the file names of a directory & trying to use getDir() function.
    But its saying AttributeError: 'module' object has no attribute 'getDir'
    Can you tell me the correct syntax to use it.

    I have one more query: - Plz tell me how to execute any command using python.
    i.e. i want to run
    sqlplus /nolog @c:\try.sql
    Can you tell me how to use it???

    Thanks & Regards.
    Piyush.
  • ghostdog74
    Recognized Expert Contributor
    • Apr 2006
    • 511

    #2
    Originally posted by cpiyush
    Hi.

    I am trying to read all the file names of a directory & trying to use getDir() function.
    But its saying AttributeError: 'module' object has no attribute 'getDir'
    Can you tell me the correct syntax to use it.

    I have one more query: - Plz tell me how to execute any command using python.
    i.e. i want to run
    sqlplus /nolog @c:\try.sql
    Can you tell me how to use it???

    Thanks & Regards.
    Piyush.
    check the os module.
    for getting file names, you can use os.listdir(), or os.walk(). you can also use glob module which supports wildcard '*'. See glob module.
    as for how to execute an external command, you can use os.system(), or the newer module called subprocess

    Comment

    • cpiyush
      New Member
      • Jan 2007
      • 31

      #3
      Thanks man...

      Comment

      Working...