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

    Join Date
    Sep 2004
    Posts
    330
    Rep Power
    15

    writing file names into a text file


    Hello,

    Is there a way to write a Python scirpt that outputs the names of all the files in a folder to a text file? I know how to manipulate the files individually, but not sure how to get their names. I want something like;

    Code:
    for file in myFolder:
        output.write(file.getname())
    Thanks for your help.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    103
    Rep Power
    11
    Originally Posted by sam_kh918
    Hello,

    Is there a way to write a Python scirpt that outputs the names of all the files in a folder to a text file? I know how to manipulate the files individually, but not sure how to get their names. I want something like;

    Code:
    for file in myFolder:
        output.write(file.getname())
    Thanks for your help.
    You might try something like this:
    Code:
    import os
    
    path = raw_input('Directory to search: ')
    
    for file in os.listdir(path):
        print file
    It is not important if the glass is half full or half empty.What is important,is who has been drinking from MY glass?!?!?
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    330
    Rep Power
    15
    Thanks alot, that perfectly does it!
    Last edited by sam_kh918; August 16th, 2005 at 10:03 PM.

IMN logo majestic logo threadwatch logo seochat tools logo