我该如何寻找它的名字使用批处理脚本文件的目录? [英] How do I search for the directory of a file given its name using a batch script?

查看:356
本文介绍了我该如何寻找它的名字使用批处理脚本文件的目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道一个文件的名字,但我不知道它位于哪个目录,我需要找到的目录。

I know the name of a file, but I don't know what directory it resides in. I need to find the directory.

给定一个文件名,我怎么可以搜索包含一个批处理脚本文件目录?

Given the name of a file, how can I search for a directory that contains this file with a batch script?

推荐答案

我假设你知道哪些驾驶它坐落在,让我们说驱动器C:

I am assuming you know which drive it is located on, let us say drive C:

如果你只是想列出所有的地点在哪里MYFILE.TXT存在,那么

If you just want to list all the locations where MYFILE.TXT exists, then

dir /b /a-d /s "c:\myfile.txt"

上面的将包括在输出的文件名。

The above will include the file name in the output.


如果你需要做一些事情的路径,让我们说ECHO的路径,但它可以是任何东西,然后


If you need to do something with the path, let us say ECHO the path, but it could be anything, then

for /r c:\ %%F in (myfile.txt) if exist "%%F" echo %%~dpF

〜DP 修改的%%˚F来只包括驱动器和路径,剥离名扩展和延伸。

The ~dp modifies the expansion of %%F to only include the drive and path, stripping the name and extension.

如果在命令行而不是从一个批处理文件运行再改双百分比为单百分比。

If run from the command line instead of from a batch file then change the double percents to single percents.


如果你不知道什么驱动文件,那么你将要运行的每个驱动器上的任何解决方案,它可能包含文件。


If you don't know what drive the file is on then you will have to run either solution on each drive that might contain the file.

这篇关于我该如何寻找它的名字使用批处理脚本文件的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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