[Tutor] Too many open files -- how to copy a folder?

Bill Campbell bill at celestial.net
Fri Oct 29 18:56:50 CEST 2004


On Thu, Oct 28, 2004, Matej Cepl wrote:
>Hi,
>
>I've tried this:
>
>blahoslav:matej$ python
>Python 2.3.4 (#2, Sep 24 2004, 08:39:09)
>[GCC 3.3.4 (Debian 1:3.3.4-12)] on linux2
>Type "help", "copyright", "credits" or "license" for more information.
>>>> import mailbox
>>>> box = mailbox.Maildir("/home/matej/WP/trash/")
>>>> another = [x for x in box]
>Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>  File "/usr/lib/python2.3/mailbox.py", line 246, in next
>IOError: [Errno 24] Too many open files:
>'/home/matej/WP/trash/cur/1098844013.6284.XKuCF:2,S'
>
>Can be done something about that? Of course, that I will use some filter in
>the mapping, but still even when I try

It would be far easier to look at the file names individually rather than
trying to suck them in like this, particularly since maildir file names
have the Unix date as the first part of the file name.  I would probably do
it something like this:

import getdate # date parsing routines
import os

cutoffdate = getdate('10/1/2003')
mdir = os.path.join(os.environ['HOME'], '/Maildir')

fh = os.popen('find %s -type f') # let find do the work for you

for file in fx.xreadlines():
	file = file.[:-1] # strip newline
	ftime, seq, host = file.split('.') # split name into parts
	if ftime < cutoffdate:
		# do something for old files
	else:
		# do somehthing else on newer files

Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
UUCP:               camco!bill  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676
URL: http://www.celestial.com/

``A human being should be able to change a diaper, plan an invasion,
butcher a hog, conn a ship, design a building, write a sonnet, balance
accounts, build a wall, set a bone, comfort the dying, take orders, give
orders, cooperate, act alone, solve equations, analyze a new problem, pitch
manure, program a computer, cook a tasty meal, fight efficiently, die
gallantly.  Specialization is for insects.'' Robert Heinlein


More information about the Tutor mailing list