title: Creating a BAT file to share multiple folders, and their sub-folders
body: <p>I have a file server with multiple folders on it that need to be shared out.  Occasionally, the shares vanish, and need to be re-shared (beyond the scope of this question, I'm dealing with that as a separate issue).  For now, I am looking for a way to easily automate the re-sharing of folders via a single BAT file when this happens, so that I am not manually re-sharing several dozen folders by hand.</p>
  
  <p>There are a limited number of specific top-level folders that need to be shared - Users, Jobs, Operations, etc. - this is not a problem so far, I can manually specify them with a NET SHARE command.</p>
  
  <p>Where I am running into an issue is for a handful of folders that need <em>all</em> of their sub-folders also shared.  For example, every folder under D:\Shares\00_Users also needs to be shared as well.</p>
  
  <p>I have a command that will share all files in the current directory, but not ones in another directory - meaning I need to leave a copy of the BAT in the share, which is not a good idea.  Is there a way I can automate this so that the BAT file will share each sub-folder in another folder?</p>
  
  <p>Here is my current code:</p>
  
  <pre><code>NET SHARE "NameOfShare=D:\Shares" /GRANT:Everyone,FULL /CACHE:None
  FOR /D %%G IN (D:\Shares\00_Users\*.*) DO NET SHARE "%%G=%%G" /GRANT:Everyone,FULL /CACHE:None
  </code></pre>
  
  <p>Where I am running into issues is the "%%G=%%G" - I want to replace the first part of the parameter with JUST the name of the folder, not the whole path.</p>
  
  <p>Ideally this would share "D:\Shares\00_Users\JSmith" as a share named "JSmith"</p>
  
  <p>Thank you for your help!</p>