Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Peter Pearson Newsgroups: comp.lang.python Subject: Re: How to use regex (re) Date: 7 Aug 2015 16:48:12 GMT Lines: 39 Message-ID: References: <306503ec-4052-4438-b778-781797f9941a@googlegroups.com> X-Trace: individual.net XjBGPUfC53UmHdRFB+P+LwUpWvFseHQKsE39eq/JUGvrOjJ3+a Cancel-Lock: sha1:iDTRN90JfdYHF53T/5v7N4OS3LA= User-Agent: slrn/pre1.0.0-18 (Linux) Xref: csiph.com comp.lang.python:95130 On Thu, 6 Aug 2015 13:06:36 -0700 (PDT), PK Khatri wrote: > I have a following script which extracts xyz.tgz and outputs to a > folder which contains several sub-folders and files. > > source_dir = "c:\\TEST" > dest_dir = "c:\\TEST" > for src_name in glob.glob(os.path.join(source_dir, '*.tgz')): > base = os.path.basename(src_name) > dest_name = os.path.join(dest_dir, base[:-4]) > with tarfile.open(src_name, 'r') as infile: > infile.extractall(dest_dir) > > When above script is ran, the output is a single directory within that > directory the structure looks like this: > > folder_1 > folder_2 > folder_n > file_1 > file_2 > file_n > > In these folder, there are sub-folders and files. Among those file > there are some data i am interested in to search and output to a file. > > For eg. Among the folders there is a file called > **'localcli_network-ip-neighbor-list.txt**' which contains IP > address(s) which I would like to output to a file. Are you asking how to determine whether the string "localcli_network-ip-neighbor-list.txt" appears in a filename? If so, the logical expression "localcli_network-ip-neighbor-list.txt" in filename will do the job. -- To email me, substitute nowhere->runbox, invalid->com.