This has been extremely helpful, thank you! I'm looking to take it one step further...
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.
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.
Where I am running into an issue is for a handful of folders that need all of their sub-folders also shared. For example, every folder under D:\Shares\00_Users also needs to be shared as well.
The above command 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?
Here is my current code:
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.
Ideally this would share "D:\Shares\00_Users\JSmith" as a share named "JSmith". Currently, it's trying to set the share name to be the full path!
Thank you for your help!