home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / Chip_2003-01_cd2.bin / convert / eJayMp3Pro / mp3pro_demo.exe / GLOB.PYC (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-10-30  |  1.9 KB  |  56 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. '''Filename globbing utility.'''
  5. import os
  6. import fnmatch
  7. import re
  8.  
  9. def glob(pathname):
  10.     '''Return a list of paths matching a pathname pattern.
  11.  
  12. \tThe pattern may contain simple shell-style wildcards a la fnmatch.
  13.  
  14. \t'''
  15.     if not has_magic(pathname):
  16.         if os.path.exists(pathname):
  17.             return [
  18.                 pathname]
  19.         else:
  20.             return []
  21.     
  22.     (dirname, basename) = os.path.split(pathname)
  23.     if has_magic(dirname):
  24.         list = glob(dirname)
  25.     else:
  26.         list = [
  27.             dirname]
  28.     return result
  29.  
  30.  
  31. def glob1(dirname, pattern):
  32.     if not dirname:
  33.         dirname = os.curdir
  34.     
  35.     
  36.     try:
  37.         names = os.listdir(dirname)
  38.     except os.error:
  39.         return []
  40.  
  41.     result = []
  42.     for name in names:
  43.         if name[0] != '.' or pattern[0] == '.':
  44.             if fnmatch.fnmatch(name, pattern):
  45.                 result.append(name)
  46.             
  47.         
  48.     
  49.     return result
  50.  
  51. magic_check = re.compile('[*?[]')
  52.  
  53. def has_magic(s):
  54.     return magic_check.search(s) is not None
  55.  
  56.