How to insert strings and slashes in a path?
<p>I'm trying to extract tar.gz files which are situated in diffent files named srm01, srm02 and srm03.
The file's name must be in input (a string) to run my code.
I'm trying to do something like this :</p>

<pre><code>import tarfile
import glob

thirdBloc = 'srm01' #Then, that must be 'srm02', or 'srm03'
for f in glob.glob('C://Users//asediri//Downloads/srm/'+thirdBloc+'/'+'*.tar.gz'):
    tar = tarfile.open(f)
    tar.extractall('C://Users//asediri//Downloads/srm/'+thirdBloc)
</code></pre>

<p>I have this error message: </p>

<pre><code>IOError: CRC check failed 0x182518 != 0x7a1780e1L
</code></pre>

<p>I want first to be sure that my code find the .tar.gz files. So I tried to just print my paths after glob: </p>

<pre><code>thirdBloc = 'srm01' #Then, that must be 'srm02', or 'srm03'
for f in glob.glob('C://Users//asediri//Downloads/srm/'+thirdBloc+'/'+'*.tar.gz'):
    print f
</code></pre>

<p>That gives :</p>

<pre><code>C://Users//asediri//Downloads/srm/srm01\20160707000001-server.log.1.tar.gz
C://Users//asediri//Downloads/srm/srm01\20160707003501-server.log.1.tar.gz
</code></pre>

<p>The os.path.exists method tell me that my files doesn't exist. </p>

<pre><code>print os.path.exists('C://Users//asediri//Downloads/srm/srm01\20160707000001-server.log.1.tar.gz')
</code></pre>

<p>That gives : False</p>

<p>Any way todo properly this work ? What's the best way to have first of all the right paths ? </p>

<p>os.path.join will create the correct paths for your filesystem</p>

<pre><code>f = os.path.join('C://Users//asediri//Downloads/srm/', thirdBloc, '*.tar.gz')
</code></pre>

python python-2.7 filepath glob tarfile