title: Batch file - Loop thru folder and get file name
body: <p>Sorry if this seems like a simple question, but I could not find the right answer anywhere....</p>
  
  <p>I have a set of files in a folder with this naming convention....
  tablename_date_time.dat</p>
  
  <p>I need to loop thru the folder and extract the tablename (up to the underscore) and use it in a bcp command, what would be the best way to do this?</p>
  
  <p>So far I have the command, but I can't figure out the substr part.</p>
  
  <pre><code>for /f %%i in (%1) do (
      bcp tablename IN C:\temp\%%i_.dat -n -T
  )
  </code></pre>
  
  <p>Thank you for your help.</p>