Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to search a file in the whole drive and take action-batch  (Read 5782 times)

0 Members and 1 Guest are viewing this topic.

Whitebeard1

    Topic Starter


    Intermediate

    Thanked: 2
    • Computer: Specs
    • Experience: Familiar
    • OS: Mac OS
    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
    Computers follow your orders, not your intentions.

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: How to search a file in the whole drive and take action-batch
    « Reply #1 on: June 07, 2013, 07:15:22 AM »
    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.

    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.

     8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    Whitebeard1

      Topic Starter


      Intermediate

      Thanked: 2
      • Computer: Specs
      • Experience: Familiar
      • OS: Mac OS
      Re: How to search a file in the whole drive and take action-batch
      « Reply #2 on: June 08, 2013, 06:28:13 AM »
      Thanks alot sidewinder. this is very helpful., its exactly what i was trying to do.
      Computers follow your orders, not your intentions.