How to prompt the user for a directory location?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Miguel Valenzue
    New Member
    • Dec 2010
    • 39

    How to prompt the user for a directory location?

    Hi, I currently am running a simple script that substitutes the comma in a text file with a period. This is basically to change a bunch of european files to american dot.
    I'd like to prompt the user and allow the user to browse for a location of the folder when the program is run.
    This is my current code.
    Code:
    path="C:\Python27\RED"
    #I need to make path browseable
    import os
    myFiles=os.listdir(path)
    
    def replaceText(myFile):
        for line in open(myFile):
            line = line.replace(",", ".")
            o.write(line)
        
    
    for x in myFiles[:]:
        myFile = x
        writeFile = "period" + x
        o = open(writeFile,"a")
        replaceText(myFile)   
        o.close()
    How does one do this in Python?
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    You can call raw_input() for the user to enter a string, or you can create a Tkinter widget such as tkFileDialog.as kopenfilename(). Other GUI toolkits have comparable widgets.

    Comment

    Working...