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

listdir returning no values for folder beginning with number

P: 2
I am using listdir on a file path that begins with a numeric character eg. 08_Data and it is not returning any values. Is there any way to correct this without changing the file name?

Thank you
Feb 24 '11 #1

✓ answered by bvdet

The backslash character is used to escape special characters such as newlines. Set your path one of these ways:
Expand|Select|Wrap|Line Numbers
  1. path = r"I:\08_TRData\01_Data_Library"
  2. path = "I:\\08_TRData\\01_Data_Library"
  3. path = "I:/08_TRData/01_Data_Library"

Share this Question
Share on Google+
3 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
Please show us the code you are using when calling listdir(). "08_Data" is a string just like "ABC" and should not cause a failure.
Feb 24 '11 #2

P: 2
Like this:

path = "I:\08_TRData\01_Data_Library"
files = os.listdir(path)
for dir in files:
......
Feb 24 '11 #3

bvdet
Expert Mod 2.5K+
P: 2,851
The backslash character is used to escape special characters such as newlines. Set your path one of these ways:
Expand|Select|Wrap|Line Numbers
  1. path = r"I:\08_TRData\01_Data_Library"
  2. path = "I:\\08_TRData\\01_Data_Library"
  3. path = "I:/08_TRData/01_Data_Library"
Feb 24 '11 #4

Post your reply

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