Searching via batch
Posted: 02 Oct 2020 03:02
Hi
Within Windows I can use the search facility and I enter part of the filename I require and it shows a list of the location(s) of the file(s) (sometimes using the wildcard option if I don't know the full filename).
Is it possible to run a batch where it either prompts the user for part of the file name (I assume it can use wildcard search) and they enter the path of the folder they want to search and it then searches for all the filenames from the user input? Is it then possible to then output just the filename and a line of the path where that file is located to a textfile?
I have the following batch script but instead of hardcoding the filename, can it be changed so that the user is a) prompted what file name to search for (with wildcards) and b) Change the location of the path it is searching?
Within Windows I can use the search facility and I enter part of the filename I require and it shows a list of the location(s) of the file(s) (sometimes using the wildcard option if I don't know the full filename).
Is it possible to run a batch where it either prompts the user for part of the file name (I assume it can use wildcard search) and they enter the path of the folder they want to search and it then searches for all the filenames from the user input? Is it then possible to then output just the filename and a line of the path where that file is located to a textfile?
I have the following batch script but instead of hardcoding the filename, can it be changed so that the user is a) prompted what file name to search for (with wildcards) and b) Change the location of the path it is searching?
Code: Select all
@echo off
setlocal
rem change to the correct directory
cd /d C:\Temp
rem count the files
dir /b new*.* /s 2> nul | find "" /v /c > %temp%\count
set /p _count=<%temp%\count
rem cleanup
del %temp%\count
rem output the number of files
echo Number of Files found : %_count%
echo.
rem list the files
echo Files are located at :
echo.
dir /b new.txt /s
dir /b new.txt /s > OUTPUT.txt
endlocal
echo.
echo.
pause