找到文件,然后复制其路径.批处理脚本 [英] Locate file, and copy its path. Batch script

查看:96
本文介绍了找到文件,然后复制其路径.批处理脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用批处理脚本来自动构建Qt项目.

I am working on a batch script to automate building a Qt project.

我遇到的一个问题是Qt的安装目录路径可能对每个用户都不相同.

One issue i am having is the fact that the install directory path of Qt may not be the same for every user.

例如,在我的系统上,mingw48_32的路径为: c:\ Qt \ Qt5.2.0 \ 5.2.0 \ mingw48_32 但是在其他人的系统上 c:\ Qt \ 5.2.0 \ mingw48_32,具体取决于他们选择如何设置它.

For example, on my system the path of my mingw48_32 is: c:\Qt\Qt5.2.0\5.2.0\mingw48_32 but on someone elses system it may be c:\Qt\5.2.0\mingw48_32 depending on how they chose to set it up.

因此,当我为qmake.exe指定路径时,我需要知道qmake.exe的路径是.

So when i am specifying the path for the qmake.exe, i need to know that the path to qmake.exe is.

如何搜索文件,然后从批处理脚本复制文件的路径?

How can i search for a file, and copy its path from a batch script?

推荐答案

whence.bat

whence.bat

不太像真正的起源,但这可能会有所帮助.

Not really like the real whence, but it might be helpful.

@SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
@SET EXITCODE=1

:: Needs an argument.

@IF "x%1"=="x" (
    @ECHO Usage: %0 ^<progName^>
    GOTO TheEnd
)

@set newline=^


@REM Previous two (2) blank lines are required. Do not change!

@REM Ensure that the current working directory is first
@REM because that is where DOS looks first.
@PATH=.;!PATH!

@FOR /F "tokens=*" %%i in ("%PATH:;=!newline!%") DO @(
    @IF EXIST %%i\%1 (
        @ECHO %%i\%1
        @SET EXITCODE=0
    )

    @FOR /F "tokens=*" %%x in ("%PATHEXT:;=!newline!%") DO @(
        @IF EXIST %%i\%1%%x (
            @ECHO %%i\%1%%x
            @SET EXITCODE=0
        )
    )
)

:TheEnd
@EXIT /B %EXITCODE%

这篇关于找到文件,然后复制其路径.批处理脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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