I'm trying to, with use of a batch file open a folder which has a specific word in it (in this case "Folder") and storing it into a variable. Is this done using Findstr?
"C:\Users\G\Documents\File Folder"
Try this:
@echo off
for /d /r %%a in ("*Folder") do set "FolderVar=%%a"
echo %FolderVar%
copy "C:/sourcefolder/somefile.txt" "%FolderVar%/somefile.txt"
start "" "%FolderVar%"
pause
Note that this looks for Folder at the end of the pathname, if it should look anywhere in the name you should replace *Folder*
with *Folder
, but that will cause all subfolders of the "Folder" folder to be found. The variable only saves the last found occurence, if you want to do something with every occurence you should put your logic inside the loop.
The start command opens the folder in explorer. You can use the copy
command to copy files to the folder.