Reputation: 47
what i am trying to achieve is a search feature that will allow the user to put in the name of a file and it will find that file and save the file's path as a variable so I'm able to use the file path later on is this possible i have not been able to find any information on this
Upvotes: 0
Views: 229
Reputation: 2886
Write a batch file like:
@echo OFF
for /f %%F in ('dir %2\%1 /s /b') do
(
<nul (set /p msg=%%~nxF )
for /f %%G in ('dir %3\%%~nxF /s /b') do
(
if exist %%G
(
@echo found at %%G
)
)
)
Now here:
%1
is the user provided file name
%2
is the user provided directory to search first.
%3
is the user provided directory to search second.
To save the details into a text file use:
FindAll MyFile.txt d:\dir1 d:\dir2 > MyFile_report.txt 2>&1
The <nul (set /p)
trick will output text to the console without a new line
Upvotes: 1