您可以在路径(或其他类似路径的字符串,如果需要)上找到可执行文件:
c:\> for %i in (cmd.exe) do @echo. %~$PATH:i
C:\WINDOWS\system32\cmd.exe
c:\> for %i in (python.exe) do @echo. %~$PATH:i
C:\Python25\python.exe
详细信息可以在帮助文本的末尾找到"for"
命令,"for /?"
但总结是:
%~i - expands %i removing any surrounding quotes.
%~fi - expands %i to a fully qualified path name.
%~di - expands %i to a drive letter only.
%~pi - expands %i to a path only.
%~ni - expands %i to a file name only.
%~xi - expands %i to a file extension only.
%~si - expanded path contains short names only.
%~ai - expands %i to file attributes of file.
%~ti - expands %i to date/time of file.
%~zi - expands %i to size of file.
%~$P:i - searches the directories listed in the P environment variable
and expands %i to the fully qualified name of the first one found.
If the environment variable name is not defined or the file is not
found by the search, then this modifier expands to the empty string.
可以组合修饰符以获得复合结果:
%~dpi - expands %i to a drive letter and path only.
%~nxi - expands %i to a file name and extension only.
%~fsi - expands %i to a full path name with short names only.
%~dp$P:i - searches the directories listed in the P environment variable
for %i and expands to the drive letter and path of the first
one found.
%~ftzai - expands %i to a DIR like output line.
如果您的可执行文件不在路径上(根据您的编辑),那么最好的选择是使用裸/子目录格式dir
这将为你做。从根目录:
dir /b /s ISTool.exe
将为您提供该驱动器上具有该名称的所有文件。然后你只需要解析输出。我自己的偏好是使用 Cygwin 的"find /cygdrive -name ISTool.exe"
但那是因为我已经安装了它。您可能不希望这样(或者甚至没有这样的选择)。
Update:
That dir /b /s
命令将需要一段时间,因为它基本上搜索整个磁盘。如果这是一个问题,您可能需要考虑使用 cmd 文件定期创建所有磁盘上所有文件的缓存记录,例如:
@echo off
setlocal enableextensions enabledelayedexpansion
del c:\files.cache.tmp >nul: 2>nul:
for %%d in (c d e) do (
cd /d %%d:\
dir /b /s >>c:\files.cache.tmp
)
del c:\files.cache >nul: 2>nul:
move c:\files.cache.tmp c:\files.cache
endlocal
您可以通过每晚(对于始终在线的服务器)或在启动时(对于桌面)计划任务来执行此操作。您甚至可以使脚本更加智能,每隔几天执行一次(我有一个自动备份脚本,可以在我支持的家庭计算机上执行类似的操作)。这会在临时缓存文件中创建列表,然后覆盖原始列表,以确保最小化文件不存在的时间。
然后你就可以使用:
findstr \\ISTool.exe c:\files.cache
找到您的所有文件。