Welcome, guest | Sign In | My Account | Store | Cart

The filesystem on Windows usually preserves the case of filenames, but is case insensitive if you are accessing files.

Python, 27 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class FileSet:
    def __init__(self, *args):
        self._dict = {}
        for arg in args:
            self.add(arg)

    def __repr__(self):
        return "<FileSet %s at %x>" % (self._dict.values(), id(self))

    def add(self, file):
        self._dict[string.upper(file)] = file

    def remove(self, file):
        del self._dict[string.upper(file)]

    def contains(self, file):
        return string.upper(file) in self._dict.keys()

    def __getitem__(self, index):
        key = self._dict.keys()[index]
        return self._dict[key]

    def __len__(self):
        return len(self._dict)

    def items(self):
        return self._dict.values()
Created by Thomas Heller on Tue, 29 Jan 2002 (PSF)
Python recipes (4591)
Thomas Heller's recipes (6)

Required Modules

  • (none specified)

Other Information and Tasks