0

我有这段代码,我写在一个 .bat 文件中,它运行良好,但是突然......它停止工作了,除了我更改了几个文件夹名称之外,我不知道它发生了什么。

这是我的代码:

@echo off  
start /w Files\MySQL\mysql-connector-net-6.6.5.msi  
echo MySQL Connector/NET 6.6.5 has been installed.  
FOR /F "usebackq delims=" %%i in (`cscript desktop.vbs`) DO SET DESKTOPDIR=%%i  
copy Files\DayZAdminApp.exe %DESKTOPDIR%\DayZ Admin Panel  
echo.  
echo DayZ Admin Panel has been placed onto your desktop.  
echo D | xcopy Files\DaRT %desktopdir%\DayZ Admin Panel\Files\DaRT /E /Q  
ping 127.0.0.1 -n 2 -w 1000 >nul: 2>nul:  
echo.  
echo DayZ Admin rCon Tool (DaRT) has been copied.  
echo.  
copy Files\loadout.exe %DESKTOPDIR%\DayZ Admin Panel\Files  
echo Loadout editor has been copied.  
echo.  
echo.  
echo Make sure you keep the folder intact, any missing files will limit the panel's capabilities.  
echo.  
pause

这是 desktop.vbs 文件:

set WshShell = WScript.CreateObject("WScript.Shell")  
strDesktop = WshShell.SpecialFolders("Desktop")  
wscript.echo(strDesktop)`

如果有帮助,这是输出的屏幕截图:

代码输出

注意:我的代码工作得很好,除了文件夹名称Files\DayZ Admin Panel\

如果是我弄乱了那些文件夹名,请告诉我我做错了什么,因为这看起来很漂亮

4

3 回答 3

2

您需要"在路径周围使用,因为包含空格

copy Files\DayZAdminApp.exe "%DESKTOPDIR%\DayZ Admin Panel"
...
echo D | xcopy Files\DaRT "%desktopdir%\DayZ Admin Panel\Files\DaRT" /E /Q
...
copy Files\loadout.exe "%DESKTOPDIR%\DayZ Admin Panel\Files"
于 2013-03-23T23:15:21.790 回答
2

只要路径有空格,您就必须使用引号:"%desktopdir%\DayZ Admin Panel\Files\DaRT"

于 2013-03-23T23:15:48.953 回答
-1

在这种情况下,您不需要 VBScript 帮助,但看起来您在将可执行文件的输出重定向到批处理变量时遇到了问题,因此我编写了一段代码,希望它对类似任务有所帮助。

@Echo OFF

Echo --- Test 1 ---
FOR /F "usebackq delims=" %%i IN (cscript desktop.vbs) DO (
   SET DESKTOPDIR=%%i
)
Echo %DESKTOPDIR%

Echo --- Test 2 ---
FOR /F "usebackq delims=" %%i IN (%windir%\system32\cscript.exe desktop.vbs) DO (
   SET DESKTOPDIR=%%i
)
Echo %DESKTOPDIR%

Pause

输出: 在此处输入图像描述

正确的一个是:

@ECHO OFF

Echo --- Test 1 ---
FOR /F "tokens=*" %%i IN ('cscript.exe desktop.vbs') DO (
   SET DESKTOPDIR=%%i
)
ECHO Desktop: %DESKTOPDIR%

REM or...

Echo --- Test 2 ---
FOR /F "usebackq delims=" %%i IN (`cscript.exe desktop.vbs`) DO (
   SET DESKTOPDIR=%%i
)
Echo Desktop: %DESKTOPDIR%

Pause
于 2013-03-24T00:11:43.483 回答