Computer Hope
Software => Computer programming => Topic started by: Whitebeard1 on June 07, 2013, 02:28:20 AM
-
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?
thanks
-
Except for automation scripts, I am a big fan of batch file prompts. It eliminates remembering command line arguments and which order they are expected.
@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.
8)
-
Thanks alot sidewinder. this is very helpful., its exactly what i was trying to do.