Files and Directories
Fredrik Lundh
effbot at telia.com
Mon Feb 7 01:49:27 EST 2000
Patrick K Moorman <khadji at pld.com> wrote:
> Thanks to everyone who answered my last question, it is good reminder that
> computers do *ONLY* what they are told. I am trying to write a little
> script that will rename files in multiple directories. What am a looking
> for is a way to take each item returned by os.listdir() and test to see if
> it is a file or a directory. I have gone through the lib reference but I
> did not see anything that would work.
http://www.python.org/doc/current/lib/module-os.path.html
-> os.path.isdir(path) and os.path.isfile(path)
for file in os.listdir("directory"):
if os.path.isdir(file):
print file, "is a directory"
also see os.path.walk(). and the os and os.path
examples in the eff-bot guide...
</F>
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list