如何在批处理中找到特定文件名并更改到该目录? [英] How do I find a Specific File Name in Batch and change to that directory?

查看:146
本文介绍了如何在批处理中找到特定文件名并更改到该目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写一个批处理文件,它将获取特定文件(curl_for_64bit.exe)的目录。我尝试使用find命令,但它不工作。

解决方案

以下脚本搜索文件的目录,在根目录树 C:\ROOT\ 中的文件 curl_for_64bit.exe ,并更改为父目录找到的文件实际位于:

  for / Fdelims =%% F in('dir / B / A:-DC:\ROOT\curl_for_64bit.exe')do(
cd / D%%〜dpF

/ pre>

或直接输入到 cmd 中的此命令行:

  for / Fdelims =%F in('dir / B / S / A:-DC:\ROOT\curl_for_64bit.exe )do @cd / D%〜dpF

要了解 〜dp 修饰符代表变量 %% F 一个新的命令提示符窗口,键入 for /?并阅读帮助文本(特别是最后一节)。


I am coding a batch file that will get the directory of a specific file(curl_for_64bit.exe). I tried using the find command but it does not work. It basically gets the directory of the file, changes to that directory so that it can be copied.

解决方案

The following script searches the file curl_for_64bit.exe in the directory tree rooted at C:\ROOT\ and changes to the parent directory where the found file is actually located:

for /F "delims=" %%F in ('dir /B /S /A:-D "C:\ROOT\curl_for_64bit.exe"') do (
    cd /D "%%~dpF"
)

Or this command line to be typed directly into cmd:

for /F "delims=" %F in ('dir /B /S /A:-D "C:\ROOT\curl_for_64bit.exe"') do @cd /D "%~dpF"

To learn what the ~dp modifier of the for variable %%F means and how it works, open a new command prompt window, type for /? and read the help text (see the last section in particular).

这篇关于如何在批处理中找到特定文件名并更改到该目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆