By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,356 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

How to prompt the user for a directory location?

P: 39
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.
Expand|Select|Wrap|Line Numbers
  1. path="C:\Python27\RED"
  2. #I need to make path browseable
  3. import os
  4. myFiles=os.listdir(path)
  5.  
  6. def replaceText(myFile):
  7.     for line in open(myFile):
  8.         line = line.replace(",", ".")
  9.         o.write(line)
  10.  
  11.  
  12. for x in myFiles[:]:
  13.     myFile = x
  14.     writeFile = "period" + x
  15.     o = open(writeFile,"a")
  16.     replaceText(myFile)   
  17.     o.close()
  18.  
How does one do this in Python?
Jan 11 '11 #1

✓ answered by bvdet

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

Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
You can call raw_input() for the user to enter a string, or you can create a Tkinter widget such as tkFileDialog.askopenfilename(). Other GUI toolkits have comparable widgets.
Jan 11 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.