SreeniH
SreeniH

Reputation: 503

Extract zipfiles on a remote server in python

I have a unique situation. I have a local zip file (C:\Temp\abc.zip). I want to extract this file in python to a remote drive (\Crprvau01n1\Cdv_prd$\DataDrop\Quartz\IMM\DevRuns). Please note that there is no drive letter. I have write permissions to this folder and I can access via windows explorer. I have this following code,

import zipfile, os

def main():
    zfile = zipfile.ZipFile("\\Crprvau01n1\Cdv_prd$\DataDrop\Quartz\IMM\DevRuns\Zinc.zip", 'r')
    for name in zfile.namelist():
        (dirname, filename) = os.path.split(name)
        print "Decompressing " + filename + " on " + dirname
        filename = "C:/Temp/" + filename
        fd = open(filename,"w")
        fd.write(zfile.read(name))
        fd.close()

I get the below error:

IOError: [Errno 2] No such file or directory: '\\Crprvau01n1\\Cdv_prd$\\DataDrop\\Quartz\\IMM\\DevRuns\\Zinc.zip'

Any suggestions on how to read the remote zip file is appreciated.

Thanks

Upvotes: 0

Views: 1772

Answers (1)

Janne Karila
Janne Karila

Reputation: 25197

Use a raw string r'...' (or double every backslash):

zipfile.ZipFile(r"\\Crprvau01n1\Cdv_prd$\DataDrop\Quartz\IMM\DevRuns\Zinc.zip", 'r')

Backslash is an escape character in normal strings.

Upvotes: 2

Related Questions