title: dynamically append processed filename to output txt file
body: <p><strong>samples</strong> folder has a bunch of samples <code>a,b,c,d,e</code>. </p>
  
  <p>while saving the final output <code>features_with_times</code> to a file, I want it to be appended with name of the file it just processed.<br>
  I approached using <a href="https://stackoverflow.com/questions/12560600/creating-a-new-file-filename-contains-loop-variable-python">Creating a new file, filename contains loop variable, python</a> ,   and I did the following, but getting small error.    </p>
  
  <pre><code>from __future__ import division
  
  import librosa
  import os
  import numpy as np
  
  
  test_src = 'samples/'
  
  path_to_audios = [os.path.join(test_src, f) for f in os.listdir(test_src)]
  
  for audio_path in path_to_audios:
      # blah ..
      # blah 
  
      # blah . . 
      # blah  . . 
  
  
      features_with_times= some_val 
      # np.savetxt('koo'+ str(k) + '.txt')
  
      print "saving mfcc features"
      np.savetxt('mfcc_flwts'+str(audio_path)+'.txt', features_with_times,newline ='\n', delimiter= '\t')
  </code></pre>
  
  <p><strong>ERROR</strong> : IOError: [Errno 2] No such file or directory: 'mfcc_flwtssamples/abc.mp3.txt'</p>
  
  <p>How to fix this ? how do _prevent the <code>samples/</code> tag from coming in between.
  I know I can have <code>names_to_append = [f for f in os.listdir(test_src)]</code>
  which will save the names of the files present in the sample/ folder. to a list. </p>
  
  <p>How do I pass these to the <code>np.savetxt()</code> step.</p>
  
  <p>Newbie question.</p>
  
  <p>UPDATE: 
  <strong>I crude solution I came up with was to subtract the two strings:</strong> </p>
  
  <pre><code>a = 'samples/'
  b = audio_path
  val = b.replace(a,'')
  np.savetxt('mfcc_flwts_'+str(val)+'.txt', features_with_times,newline ='\n', delimiter= '\t')
  </code></pre>
  
  <p>Is there a better way to achieve my solution.</p>
  
  <p>UPDATE : 2 : </p>
  
  <p><strong>I am also able to save it to a folder of my choice as follows:</strong></p>
  
  <pre><code>save_destination = 'outputss/'
      np.savetxt(os.path.join(save_destination,'mfcc_flwts_'+str(val)+'.txt'), features_with_times,newline ='\n', delimiter= '\t')
  </code></pre>