Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does batch bat search the specified file to get its full path?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how batch bat to achieve a comprehensive search of specified files to get its complete path, I believe that most people do not understand, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

If you want to use it, you can save it as a bat file.

[scheme 1] for / f + dir

@ echo offrem specifies the file to be searched set "FileName=BatHome_Batcher.txt" echo is searching Just a moment, please. For% an 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 / Amurd / s / b "% a:\ *% FileName%" 2 ^ > nul') do (if / I "% ~ nxb" equ "% FileName%" (echo,%%b)

[option 2] for / r (more efficient than for / f + dir, but does not traverse hidden files)

@ echo offrem specifies the file to be searched set "FileName=BatHome_Batcher.txt" echo is searching Please wait... for% an 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))

[scheme 3] WMIC (Win2000/WinXP HOME version and WinXP Lite version may not support it)

@ echo offrem specifies that set "FileName=BatHome_Batcher.txt" echo is searching. Please wait... for% an in ("% FileName%") do (set "nName=%%~na" set "xName=%%~xa") set "xName=%xName:~1%" for / f "skip=1 delims="% an in ('wmic datafile where "filename='%nName%' and Extension='%xName%'" get name') do (echo,%%a)

[scheme 4] use the where command that comes with the Windows7 system

@ echo offrem specifies the file to be searched set "FileName=BatHome_Batcher.txt" echo is searching Please wait... for% an 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%" (echo) % b) these are all the contents of the article "how does batch bat search a specified file to get its full path" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report