Read a group of files as a list

Steve Holden steve at holdenweb.com
Mon Sep 18 20:38:49 EDT 2006


citlaly wrote:
> Hi!!
> I'm a beginner in python and I'm trying to use the files from a
> "folder" as a list. What I want to do is  read each one as a list, but
> just the name of the file, the data inside doesn't matter. How can I do
> it?  I was trying using a list, but I don't know how "convert" the
> elements (files) to a list that I can read and manipulate...
> 
> Thanks in advance for your help!!
> 
C:\Steve\wordpress>dir
  Volume in drive C has no label.
  Volume Serial Number is 9CA8-2A02

  Directory of C:\Steve\wordpress

08/15/2005  12:02 AM    <DIR>          .
08/15/2005  12:02 AM    <DIR>          ..
02/13/2005  04:38 PM                95 index.php
04/01/2003  10:12 AM            15,127 license.txt
05/27/2005  01:51 PM             8,781 readme.html
08/15/2005  12:02 AM    <DIR>          wp-admin
05/09/2005  07:11 AM             1,972 wp-atom.php
05/13/2005  05:07 PM             8,641 wp-blog-header.php
05/03/2005  03:31 AM             2,365 wp-comments-post.php
08/14/2005  02:21 PM             3,369 wp-commentsrss2.php
02/21/2005  02:38 AM               840 wp-config-sample.php
08/15/2005  12:02 AM    <DIR>          wp-content
03/29/2005  11:05 AM               762 wp-feed.php
08/15/2005  12:02 AM    <DIR>          wp-images
08/15/2005  12:02 AM    <DIR>          wp-includes
03/22/2005  05:56 PM             2,319 wp-links-opml.php
06/26/2005  12:27 PM             9,864 wp-login.php
02/01/2005  09:21 AM             5,591 wp-mail.php
03/13/2005  12:36 PM               299 wp-pass.php
02/21/2005  12:19 AM             2,346 wp-rdf.php
04/18/2005  11:35 PM             6,525 wp-register.php
02/21/2005  12:19 AM             1,345 wp-rss.php
02/24/2005  02:29 PM             2,100 wp-rss2.php
08/14/2005  11:57 PM             5,840 wp-settings.php
04/20/2005  06:06 PM             3,069 wp-trackback.php
02/14/2005  12:36 AM             1,922 wp.php
08/14/2005  02:06 PM            38,304 xmlrpc.php
               21 File(s)        121,476 bytes
                6 Dir(s)  15,239,180,288 bytes free

C:\Steve\wordpress>python
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
Started with C:/Steve/.pythonrc
  >>> import glob
  >>> glob.glob("*")
['index.php', 'license.txt', 'readme.html', 'wp-admin', 'wp-atom.php', 
'wp-blog-header.php', 'wp-comments-post.php', 'wp-commentsrss2.php', 
'wp-config-sample.php', 'wp-content', 'wp-feed.php', 'wp-images', 
'wp-includes', 'wp-links-opml.php', 'wp-login.php', 'wp-mail.php', 
'wp-pass.php', 'wp-rdf.php', 'wp-register.php', 'wp-rss.php', 
'wp-rss2.php', 'wp-settings.php', 'wp-trackback.php', 'wp.php', 
'xmlrpc.php']

There are os.path functions that will tell you whether a particular file 
name (fn) is a directory or a plain file.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list