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

Time:02-19

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

C:\Users\kj\Scripts\Sh\Result\Wk6

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?

CodePudding user response:

for zipping the file you can use following:

from zipfile import ZipFile
import os

path = r'C:\Users\kj\Scripts\Sh\Result\Wk6'
os.chdir(path)
ZipFile('<new path>/name.zip', 'w').write('Wk6.csv')

CodePudding user response:

Thankyou for your reply @Alex_Wlt. The problem is , it zips the file but the size of the file remains same due to some reason. Can you please recommend something.

  • Related