python - How to insert strings and slashes in a path? -
i'm trying extract tar.gz files situated in diffent files named srm01, srm02 , srm03. file's name must in input (a string) run code. i'm trying :
import tarfile import glob thirdbloc = 'srm01' #then, must 'srm02', or 'srm03' f in glob.glob('c://users//asediri//downloads/srm/'+thirdbloc+'/'+'*.tar.gz'): tar = tarfile.open(f) tar.extractall('c://users//asediri//downloads/srm/'+thirdbloc)
i have error message:
ioerror: crc check failed 0x182518 != 0x7a1780e1l
i want first sure code find .tar.gz files. tried print paths after glob:
thirdbloc = 'srm01' #then, must 'srm02', or 'srm03' f in glob.glob('c://users//asediri//downloads/srm/'+thirdbloc+'/'+'*.tar.gz'): print f
that gives :
c://users//asediri//downloads/srm/srm01\20160707000001-server.log.1.tar.gz c://users//asediri//downloads/srm/srm01\20160707003501-server.log.1.tar.gz
the os.path.exists method tell me files doesn't exist.
print os.path.exists('c://users//asediri//downloads/srm/srm01\20160707000001-server.log.1.tar.gz')
that gives : false
any way todo work ? what's best way have first of right paths ?
in order join paths have use os.path.join
follow:
import os import tarfile import glob thirdbloc = 'srm01' #then, must 'srm02', or 'srm03' f in glob.glob(os.path.join('c://users//asediri//downloads/srm/', thirdbloc, '*.tar.gz'): tar = tarfile.open(f) tar.extractall(os.path.join('c://users//asediri//downloads/srm/', thirdbloc))
Comments
Post a Comment