title: Python glob, os, relative path, making filenames into a list
body: <p>I am trying to make a list of all files in a directory with filenames in a that end in .root.</p>
  
  <p>After reading some writings in the forum I tried to basic strategies using glob and os.listdir but I got into trouble for both of them</p>
  
  <p>First, when I use</p>
  
  <pre><code>import glob
  filelist = glob.glob('/home/usr/dir/*.root')
  </code></pre>
  
  <p>It does make a list of string with all filenames that end in .root but I still face a problem.</p>
  
  <p>I would like to be the list of string to have filenames as '/dir/<em>.root' but the string has full path '/home/usr/dir/</em>.root'</p>
  
  <p>Second, if I use os.listdir, I get into the trouble that </p>
  
  <pre><code>  path = '/home/usr/'
    filelist = os.listdir(path + 'dir/*.root')
    syntax error
  </code></pre>
  
  <p>which tells me that I can not only get the list of files for .root.</p>
  
  <p>In summary, I would like to make a list of filenames, that end in .root and are in my /home/usr/dir, while cutting off the '/home/usr' part. If I use globe, I get into the trouble of having /home/usr/. If I use os.listdir, I can't specify ".root" endling.</p>