|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | + |
| 4 | +import os |
| 5 | +for root,dirs,files in os.walk("/Users/cxhuan/Downloads/globtest/hello"): |
| 6 | + for dir in dirs: |
| 7 | + print(os.path.join(root, dir)) |
| 8 | + for file in files: |
| 9 | + print(os.path.join(root, file)) |
| 10 | + |
| 11 | +import os |
| 12 | +files = list() |
| 13 | +def dirAll(pathname): |
| 14 | + if os.path.exists(pathname): |
| 15 | + filelist = os.listdir(pathname) |
| 16 | + for f in filelist: |
| 17 | + f = os.path.join(pathname, f) |
| 18 | + if os.path.isdir(f): |
| 19 | + dirAll(f) |
| 20 | + else: |
| 21 | + dirname = os.path.dirname(f) |
| 22 | + baseName = os.path.basename(f) |
| 23 | + if dirname.endswith(os.sep): |
| 24 | + files.append(dirname+baseName) |
| 25 | + else: |
| 26 | + files.append(dirname+os.sep+baseName) |
| 27 | + |
| 28 | +dirAll("/Users/cxhuan/Downloads/globtest/hello") |
| 29 | +for f in files: |
| 30 | + print(f) |
| 31 | + |
| 32 | +import glob |
| 33 | +import os |
| 34 | + |
| 35 | +for p in glob.glob('/Users/cxhuan/Downloads/globtest/*'): |
| 36 | + print(p) |
| 37 | + |
| 38 | +print('----------------------') |
| 39 | + |
| 40 | +for p in glob.glob('/Users/cxhuan/Downloads/globtest/*/*'): |
| 41 | + print(p) |
| 42 | + |
| 43 | +print('----------------------') |
| 44 | + |
| 45 | +for p in glob.glob('/Users/cxhuan/Downloads/globtest/hello/*3.txt'): |
| 46 | + print(p) |
| 47 | + |
| 48 | +print('----------------------') |
| 49 | + |
| 50 | +for p in glob.glob('/Users/cxhuan/Downloads/globtest/hello/hello?.txt'): |
| 51 | + print(p) |
| 52 | + |
| 53 | +print('----------------------') |
| 54 | + |
| 55 | +for p in glob.glob('/Users/cxhuan/Downloads/globtest/hello/*[0-2].*'): |
| 56 | + print(p) |
| 57 | + |
| 58 | +print('----------------------') |
| 59 | + |
| 60 | +p = glob.glob('/Users/cxhuan/Downloads/globtest/hello/hello?.*') |
| 61 | +print(p) |
| 62 | + |
| 63 | +print('----------------------') |
| 64 | + |
| 65 | +p = glob.iglob('/Users/cxhuan/Downloads/globtest/hello/hello?.*') |
| 66 | +print(p) |
| 67 | +print(p.__next__()) |
| 68 | +print(p.__next__()) |
| 69 | + |
| 70 | + |
0 commit comments