How does batch bat search the specified file to get its full path?
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!