473,503 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Code works in current dir only?

Does anyone know why the following code successfully labels (with [f|d|?])
entries in the current directory, but not in any other
directory? (All other directories' entries print [?].)

I'm using Python 2.5.1 on Cygwin.

Thanks!

import os

# collect all files and their paths
def collectinfo(path):
files = os.listdir(path)
files.sort()
for n in files:
if os.path.isdir(n):
print "[d]", n
elif os.path.isfile(n):
print "[f]", n
else:
print "[?]", n

# this works
if __name__ == "__main__":
collectinfo(".")

# this does not work, always labels with [?]
#if __name__ == "__main__":
# collectinfo("/")
--
Paxton Sanders
pc*******@yahoo.com
Aug 15 '08 #1
2 1052
Paxton Sanders <pc*******@yahoo.comwrites:
Does anyone know why the following code successfully labels (with [f|d|?])
entries in the current directory, but not in any other
directory? (All other directories' entries print [?].)

I'm using Python 2.5.1 on Cygwin.

Thanks!

import os

# collect all files and their paths
def collectinfo(path):
files = os.listdir(path)
files.sort()
for n in files:
n = os.path.join(path, n) ### <== you need this
if os.path.isdir(n):
print "[d]", n
elif os.path.isfile(n):
print "[f]", n
else:
print "[?]", n

# this works
if __name__ == "__main__":
collectinfo(".")

# this does not work, always labels with [?]
#if __name__ == "__main__":
# collectinfo("/")
--
Dieter Deyke
Aug 15 '08 #2
>Does anyone know why the following code successfully labels (with
>[f|d|?]) entries in the current directory, but not in any other
directory? (All other directories' entries print [?].)
n = os.path.join(path, n) ### <== you need this

Oops, there it is: my stupidity on display forever.

Thanks for the catch! :)

--
Paxton Sanders
pc*******@yahoo.com
Aug 15 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

53
5656
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
1
1306
by: DiskMan | last post by:
System: Redhat 7.2 Kernel-2.6.11.8 GCC-3.4.3 CCC-6.5.9 Binutils-2.15 Make-3.80 GTK/GLIB-2.6.7 For some reason my Linux box is suddenly having issues trying to read ;
4
3985
by: hugo2 | last post by:
Most of these characters are not on the standard keyboard. Here's a successful contrivance, with comments & cautions, a little page that works in IE6. <HTML><HEAD><SCRIPT TYPE="text/javascript">...
3
13050
by: Lachlan Hunt | last post by:
Hi, I've been looking up lots of documentation and trying to work out a cross-platform method of capturing a keyboard event and working out which key was pressed. From what I can find, there...
1
1960
by: LenS | last post by:
If this is the wrong place to post this, please advise better place. Otherwise, I have created the following python program and it works. Running on XP. I think I am now at that stage of learning...
11
18804
by: Jozef | last post by:
I have some old code that I use from the Access 95 Developers handbook. The code works very well, with the exception that it doesn't seem to recognize wide screens, and sizes tab controls so that...
18
3137
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
6
1692
by: Jéjé | last post by:
Hi, I have a custom aspx page which access RS (Reporting Services) using the webservice interface. I'm using the delegation (defautcredentialcache) to send the user authentication to RS. RS...
88
7953
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
0
984
by: Allen | last post by:
Hi Everybody, I would appreciate it if you can give me a hand here. I want to use the two codes, below, together to do the following when the "IN" button is clicked (InBtn_Click):- 1-...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.