Batch processing (BAT) to achieve a comprehensive search the specified file gets its full path method Daquan _dos/bat

Source: Internet
Author: User

Nonsense not to say, directly on the code, the amount, if you want to use, you can save yourself into a bat file.

"Scheme one" for/f + dir

@echo off
rem Specify the file to search for the
set "Filename=bathome_batcher.txt"
Echo is searching, please wait ...
For%%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
  if exist%%a:\ (
    for/f "delims="%%b in (' dir/a-d/s/b '%%a:\*%filename% ' 2^>nul ') do (if/i "%%~NXB" equ "%filename%")
      (
   echo,%%b)))

"Scheme II" for/r (more efficient than for/f + dir, but does not traverse hidden files)

@echo off
rem Specify the file to search for the
set "Filename=bathome_batcher.txt"
Echo is searching, please wait ...
For%%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
  if exist%%a:\ (
    pushd%%a:\
    for/r%%b in (*%filename%) do (if/i "%%~NXB"
      equ "%filename%" (
        echo,%%b
      )
    )
    popd
  )
)

"Scenario three" WMIC (Win2000/winxp home version, WinXP Lite version may not be supported)

@echo off
rem Specify the file to search for the
set "Filename=bathome_batcher.txt"
Echo is searching, please wait ...
For%%a in ('%filename% ') do (
  set "Nname=%%~na"
  Set "Xname=%%~xa"
)
Set "xname=%xname:~1%"
for/f " Skip=1 delims= "%%a in" (' WMIC datafile where ' filename= '%nname% ' and extension= ' ' ' "' Get Name ') does (
  %xname% 1/>)

"Scenario Four" uses the where command with the WINDOWS7 system

@echo off
rem Specify the file to search for the
set "Filename=bathome_batcher.txt"
Echo is searching, please wait ...
For%%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
  if exist%%a:\ (
    for/f "delims="%%b in ("Where/r%%a:"%filename% "2^>nul") Do (
      if/i "%%~NXB" equ "%filename%" (
        e) cho,%%b)))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.