Skip to content
Advertisement

Find a Excel file in directory, compress and send it to another folder

I have an Excel file WK6 that is downloaded in the below folder:

C:UserskjScriptsShResultWk6

The Python script should first navigate till the above directory and then find the excel file WK6 (the name of the excel file changes as per week) and compress it. Then move it to some other directory.

Please help me understand how can I find and compress the file in python?

Advertisement

Answer

for zipping the file you can use following:

from zipfile import ZipFile
import os

path = r'C:UserskjScriptsShResultWk6'
os.chdir(path)
ZipFile('<new path>/name.zip', 'w').write('Wk6.csv')
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement