简体   繁体   English

批处理文件目录和exe文件

[英]Batch file directories and exe files

I've read related posts on this forum an others for the past 6 hours which are close to my question but haven't managed to figure out a solution. 在过去的6个小时里,我已经阅读了该论坛上的其他相关帖子,这些帖子与我的问题很接近,但是还没有找到解决方案。

I'm looking to make a batch file to check if a directory exists, and if it does, execute an exe file within that directory. 我正在寻找一个批处理文件来检查目录是否存在,如果存在,请在该目录中执行一个exe文件。 If the directory does not exists I wish it to check another directory for the same exe file and execute it. 如果该目录不存在,则希望它检查另一个目录中的相同exe文件并执行它。 Furthermore I need to be able to execute the exe file with certain parameters. 此外,我需要能够使用某些参数执行exe文件。

For example: 例如:

Directory number 1 to check: C:\\Program Files\\Test\\ if it exists execute Test.exe 要检查的目录号1:C:\\ Program Files \\ Test \\(如果存在)执行Test.exe

and if this doesn't exist.. 如果不存在

Directory number 2 to check: C:\\Program Files\\Test2\\ if it exists execute Test.exe 要检查的目录号2:C:\\ Program Files \\ Test2 \\(如果存在),执行Test.exe

Hope the information is sufficient, thanks in advance! 希望信息足够,在此先感谢!

if exist c:\windows echo true

This will match a file or folder. 这将匹配文件或文件夹。 to see if a folder or not 看看是否有文件夹

pushd c:\windows&if not errorlevel 1 echo Is a folder

But why not just direct instead of stupidly testing things. 但是,为什么不直接指导而不是愚蠢地测试事物呢?

C:\windows\notepad.exe&if not errorlevel 1 c:\windows\system32\notepad.exe

or 要么

c:\windows\notepad.exe||c:\windows\system32\notepad.exe||Echo Neither File Found

& seperates commands on a line.

&& executes this command only if previous command's errorlevel is 0.

|| (not used above) executes this command only if previous command's errorlevel is NOT 0

> output to a file

>> append output to a file

< input from a file

| output of one command into the input of another command

^ escapes any of the above, including itself, if needed to be passed to a program

Try a different approach if you want to check for a specific path .. 如果要检查特定路径,请尝试其他方法。

  @echo off

  Set path1=C:\Program Files\Test

  Set path2=C:\Program Files\Test2

  setlocal enabledelayedexpansion

  for /r c: %%a in (*) do (

          call :check "%%~pa"

  )

  :check

  If "%~1"=="!path1!" (

        Call "!path1!\test.exe"

  )

  If "%~1"=="!path2!" (

         Call "!path2!\test.exe"

  )

Test this: 测试一下:

@echo off
if exist "C:\Program Files\Test\" (
   cd /d "C:\Program Files\Test\"
   "text.exe" param1 param2
 ) else (
   if exist "C:\Program Files\Test2\" cd /d "C:\Program Files\Test2\" & "text.exe" param1 param2
)
pause

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从具有批处理文件的多个目录重命名EXE - Rename EXE's from multiple directories w/ batch file 如何从不同目录中的其他批处理文件中的批处理文件中启动exe文件? - How to launch an exe file from a Batch file within an other batch file from different directories? 批处理文件以创建目录并根据部分文件名移动文件 - Batch file to create directories and move files based on partial file names 将文本文件中命名的文件批量移动到文本文件提供的目录中 - Batch move files named in a text file to directories provided by text file 批处理文件以对多个目录中的所有文件执行命令 - batch file to execute a command on all files in multiple directories 批处理文件以比较2个目录并获取不同文件的名称[dos] - Batch file to compare 2 directories and get names of files that are different [dos] 从批处理文件计算每个目录级别的文件和目录 - Counting files and directories at each directory level from a batch file 批处理文件以列出其他目录中的所有txt文件 - batch file to list all txt files from other directories Windows批处理文件递归通过目录来处理文件? - Windows Batch File Recursion Through Directories to Process Files? Windows 批处理文件通过目录循环处理文件? - Windows Batch File Looping Through Directories to Process Files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM