So I'm currently writing a batch script that will generate a file based on a folder name.
The main issue I'm stuck with is returning a string within my path when it contains a certain substring. To elaborate:
The path I'm currently looking at:
someOtherFolders\Project_Banana\05_Processing\05_Logs
Now what I will need to get is "Project_Banana". The only thing that's always fixed with this string is that it starts with "Project_" but everything else in the folder structure can differentiate (being the actual project name "Banana" in this case, where the folder is located in the path,etc.).
Only things I found were related to findstr and would just return true or false, but that's not what I want.
Best Answer
Below is a good starting point using a batch script with a FOR loop simply echoing the path example as per your question and using batch variable substrings accordingly. You can easily replace the
ECHO
command within the loop with a DIR command to list the directories if that's what you need; just adjust theTOKEN
number accordingly and test. You can replace theECHO !str!
with whatever other command(s) you need the script to process.Batch Script 1
Result
Batch Script 2
Potentially Helpful
Further Resources