Batch file 批处理文件没有给出正确的响应

Batch file 批处理文件没有给出正确的响应,batch-file,Batch File,我有一个批处理文件,我需要检查是否存在文本文件。如果检测到该文件,则应启动excel电子表格。如果它没有检测到文件,它应该将一些文件复制到不同的位置。它还需要查看windows的版本是32位还是64位 这是我的批处理文件,当前无法正常工作 @echo off for /f "tokens=*" %%a in ('dir /b /s "%windir%\system32\xcopy.exe"') do set path=%path%;%%~dpa REM check if windows 64-

我有一个批处理文件,我需要检查是否存在文本文件。如果检测到该文件,则应启动excel电子表格。如果它没有检测到文件,它应该将一些文件复制到不同的位置。它还需要查看windows的版本是32位还是64位

这是我的批处理文件,当前无法正常工作

@echo off
for /f "tokens=*" %%a in ('dir /b /s "%windir%\system32\xcopy.exe"') do set path=%path%;%%~dpa

REM check if windows 64-bit

IF EXIST "%systemdrive%\Program Files (x86)\Auto-BF\installed.txt" (
cd  "%systemdrive%\Program Files (x86)\Auto-BF"
start abf.xlsx
exit
) else (



REM check if windows 32-bit

IF EXIST "%systemdrive%\Program Files\Auto-BF\installed.txt" (
cd  "%systemdrive%\Program Files\Auto-BF"
start abf.xlsx
exit
) else (

REM create Auto-BF Folder
cd "%userprofile%\MarketFeeder Pro 7\profiles\"
md Auto-BF

REM move files_if 64-bit windows
xcopy "c:\Program Files (x86)\Auto-BF\settings.ini" "%userprofile%\MarketFeeder Pro 7\profiles\Auto-BF" /h /q /r /y
xcopy "c:\Program Files (x86)\Auto-BF\customcells.xml" "%userprofile%\MarketFeeder Pro 7\profiles\Auto-BF" /h /q /r /y
xcopy "c:\Program Files (x86)\Auto-BF\ukhorsewin.mfl" "%userprofile%\MarketFeeder Pro 7\mlocator" /h /q /r /y
xcopy "c:\Program Files (x86)\Auto-BF\auto-bf_trial.mft" "%userprofile%\MarketFeeder Pro 7\triggers" /h /q /r /y

REM move files_if 32-bit windows
xcopy "c:\Program Files\Auto-BF\settings.ini" "%userprofile%\MarketFeeder Pro 7\profiles\Auto-BF" /h /q /r /y
xcopy "c:\Program Files\Auto-BF\customcells.xml" "%userprofile%\MarketFeeder Pro 7\profiles\Auto-BF" /h /q /r /y
xcopy "c:\Program Files\Auto-BF\ukhorsewin.mfl" "%userprofile%\MarketFeeder Pro 7\mlocator" /h /q /r /y
xcopy "c:\Program Files\Auto-BF\auto-bf_trial.mft" "%userprofile%\MarketFeeder Pro 7\triggers" /h /q /r /y

ECHO Auto-BF is successfully installed - Program will now launch
PAUSE

cd "%systemdrive%\Program Files\Auto-BF\"
start abf.xlsx
EXIT

我建议尝试以下批处理文件:

@echo off
for /f "tokens=*" %%a in ('dir /b /s "%windir%\system32\xcopy.exe"') do set path=%path%;%%~dpa

REM check if Windows 64-bit

IF EXIST "%ProgramFiles(x86)%\Auto-BF\installed.txt" (
   cd /D "%ProgramFiles(x86)%\Auto-BF"
   start abf.xlsx
   goto EndOfBatch
)

REM check if Windows 32-bit

IF EXIST "%ProgramFiles%\Auto-BF\installed.txt" (
   cd /D "%ProgramFiles%\Auto-BF"
   start abf.xlsx
   goto EndOfBatch
)

REM create Auto-BF Folder
cd /D "%userprofile%\MarketFeeder Pro 7\profiles\"
md Auto-BF

IF EXIST "%ProgramFiles(x86)%\Auto-BF\*.*" (
   REM move files_if 64-bit Windows
   xcopy "%ProgramFiles(x86)%\Auto-BF\settings.ini" "%userprofile%\MarketFeeder Pro 7\profiles\Auto-BF" /h /q /r /y
   xcopy "%ProgramFiles(x86)%\Auto-BF\customcells.xml" "%userprofile%\MarketFeeder Pro 7\profiles\Auto-BF" /h /q /r /y
   xcopy "%ProgramFiles(x86)%\Auto-BF\ukhorsewin.mfl" "%userprofile%\MarketFeeder Pro 7\mlocator" /h /q /r /y
   xcopy "%ProgramFiles(x86)%\Auto-BF\auto-bf_trial.mft" "%userprofile%\MarketFeeder Pro 7\triggers" /h /q /r /y
) else (
   REM move files_if 32-bit Windows
   xcopy "%ProgramFiles%\Auto-BF\settings.ini" "%userprofile%\MarketFeeder Pro 7\profiles\Auto-BF" /h /q /r /y
   xcopy "%ProgramFiles%\Auto-BF\customcells.xml" "%userprofile%\MarketFeeder Pro 7\profiles\Auto-BF" /h /q /r /y
   xcopy "%ProgramFiles%\Auto-BF\ukhorsewin.mfl" "%userprofile%\MarketFeeder Pro 7\mlocator" /h /q /r /y
   xcopy "%ProgramFiles%\Auto-BF\auto-bf_trial.mft" "%userprofile%\MarketFeeder Pro 7\triggers" /h /q /r /y
)
ECHO Auto-BF is successfully installed - Program will now launch
PAUSE

cd /D "%ProgramFiles%\Auto-BF\"
start abf.xlsx

:EndOfBatch
它使用环境变量ProgramFilesx86和ProgramFiles,其中第一个变量在具有32位窗口的计算机上不存在,这导致将ProgramFilesx86替换为空字符串

如果当前工作目录与要更改的目录位于不同的驱动器上,则在每个cd命令上使用选项/D

它还解决了批处理文件的主要问题:通过完全避免嵌套的IF命令,使用不正确的IF命令嵌套IF命令

您的IF用法:

IF EXIST "%systemdrive%\Program Files (x86)\Auto-BF\installed.txt" (
   rem ...
   exit
) else (
   IF EXIST "%systemdrive%\Program Files\Auto-BF\installed.txt" (
      rem ...
      exit
   ) else (
      rem Where are the closing parentheses for the nested IF commands?

最后,我喜欢批处理文件的1个退出点,因此使用了goto命令而不是exit。

似乎没有任何区别……我尝试添加了一些其他语句……它们似乎都不起作用。哪个部分不起作用?哪些部分可以工作?您看到了什么错误?您没有为else语句添加右括号。