Monday, September 12, 2016

Python File Search(Pattern Marching)


Q: search all files that contain 'lib' under  directory 'c:\dev\go\ ' including sub directory,
A: glob.iglob('c:\dev\go\**\*lib*', recursive=True)

C:\Dev\Go>python
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import glob
>>> for filename in glob.iglob('c:\dev\go\**\*lib*', recursive=True):
...     print(filename)
...
c:\dev\go\lib
c:\dev\go\blog\content\spotlight-on-external-go-libraries.article
c:\dev\go\blog\content\third-party-libraries-goprotobuf-and.article
c:\dev\go\misc\cgo\testcarchive\src\libgo
c:\dev\go\misc\cgo\testcarchive\src\libgo2
c:\dev\go\misc\cgo\testcarchive\src\libgo3
c:\dev\go\misc\cgo\testcarchive\src\libgo4
c:\dev\go\misc\cgo\testcarchive\src\libgo\libgo.go
c:\dev\go\misc\cgo\testcarchive\src\libgo2\libgo2.go
c:\dev\go\misc\cgo\testcarchive\src\libgo3\libgo3.go
c:\dev\go\misc\cgo\testcarchive\src\libgo4\libgo4.go
c:\dev\go\misc\cgo\testcshared\src\libgo
c:\dev\go\misc\cgo\testcshared\src\libgo2
c:\dev\go\misc\cgo\testcshared\src\libgo4
c:\dev\go\misc\cgo\testcshared\src\libgo5
c:\dev\go\misc\cgo\testcshared\src\libgo\libgo.go
c:\dev\go\misc\cgo\testcshared\src\libgo2\libgo2.go
c:\dev\go\misc\cgo\testcshared\src\libgo4\libgo4.go
c:\dev\go\misc\cgo\testcshared\src\libgo5\libgo5.go
c:\dev\go\misc\tour\static\lib
c:\dev\go\misc\tour\static\lib\codemirror\lib
c:\dev\go\pkg\windows_amd64\compress\zlib.a
c:\dev\go\pkg\windows_amd64_race\compress\zlib.a
c:\dev\go\src\cmd\compile\internal\big\calibrate_test.go
c:\dev\go\src\cmd\internal\unvendor\golang.org\x\arch\x86\x86asm\testdata\lbmach8db.c
c:\dev\go\src\cmd\link\internal\ld\lib.go
c:\dev\go\src\compress\zlib
c:\dev\go\src\go\types\stdlib_test.go
c:\dev\go\src\image\png\testdata\invalid-zlib.png
c:\dev\go\src\math\big\calibrate_test.go
c:\dev\go\src\runtime\cgo\gcc_libinit.c
c:\dev\go\src\runtime\cgo\gcc_libinit_linux_ppc64x.c
c:\dev\go\src\runtime\cgo\gcc_libinit_openbsd.c
c:\dev\go\src\runtime\cgo\gcc_libinit_windows.c
c:\dev\go\src\runtime\cgo\libcgo.h
c:\dev\go\test\fixedbugs\bug322.dir\lib.go
c:\dev\go\test\fixedbugs\bug424.dir\lib.go
>>>

No comments:

Post a Comment