I am looking for some examples of a .bat OR .wsh script that can do the following:
TIA.
EDIT:
Oops, I should clarify: there are two directories and two searches here.
Search 1:
Search 2:
So, if Search 1 finds foo.dll, foo2.dll and foo3.dll in Dir 1, Search 2 should look in Dir 2 for foo.dll, foo2.dll and foo3.dll, and provide a report (simple listing) of each found file.
A batch file is a script file that stores commands to be executed in a serial order. It helps automate routine tasks without requiring user input or intervention. Some common applications of batch files include loading programs, running multiple processes or performing repetitive actions in a sequence in the system.
A BAT file is known as a batch file runs with DOS and all versions of Windows, under cmd.exe. It consists of a series of line commands in plain text to be executed by the command-line interpreter to perform different tasks, such as running maintenance utilities within Windows or starting typical programs.
Batch Scripting consists of a series of commands to be executed by the command-line interpreter, stored in a plain text file. It is not commonly used as a programming language and so it is not commonly practiced and is not trending but its control and dominance in the Windows environment can never be neglected.
Why not use dir?
Search current directory and all subdirs for dlls
dir /S *.dll
Search all of C for dlls
dir /S C:\*.dll
Save a report
dir /S C:\*.dll > report.txt
Put the following in a .bat file, say FindAll.bat
:
@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
)
)
)
%1
is the user provided file mask.
%2
is the user provided directory to search first.
%3
is the user provided directory to search second.
Call from the command line to generate a report:
FindAll *.dll d:\dir1 d:\dir2 > dll_report.txt 2>&1
The <nul (set /p)
trick will output text to the console without a new line (courtesy Pax from this thread: How to code a spinner for waiting processes in a Batch file?)
The 2>&1
added when calling the batch file is needed to capture all the output to the file (courtesy aphoria from this thread: Underused features of Windows batch files)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With