Hi,

We need to zip files having '2009' in their names from a particular directory. How can we do the same.

Code:
file = zipfile.ZipFile("test.zip", "w")
os.chdir(rawFileLocation)
dirList = os.listdir(rawFileLocation)
for fnames in dirList:
file.write(fnames)
file.close()
It is zipping all the files. Please tell me the logic for adding files which fulfill certain criteria only.

Regards,

If you implement glob you can use unix-style path completion ie glob.glob('*2009*.txt')

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.