1.

Solve : How to search a file in the whole drive and take action-batch?

Answer»

Hey guys i know i asked questions a lot, but IM new to batch. So i want to make a batch file find a file anywhere in the drive and take action(eg, delete it, rename it.)
will IF EXIST work?
thanksExcept for automation scripts, I am a big fan of batch file PROMPTS. It eliminates remembering COMMAND line arguments and which order they are expected.

Code: [Select]@echo off
setlocal

set /p drive=Enter Drive:
set /p arg=Enter SEARCH String:

if .%arg%==. (
for /f "tokens=* delims=" %%i in ('dir %drive%:\ /a-d /s /b') do (
echo %%i
)
) else (
for /f "tokens=* delims=" %%i in ('dir %drive%:\ /a-d /s /b ^| find /i "%arg%"') do (
echo %%i
)
)

User is prompted for both the drive letter and the file name. File names are searched to match the string entered by the user. Partial file names can be used.

Thanks alot sidewinder. this is very helpful., its exactly what i was trying to do.



Discussion

No Comment Found