批处理文件,用于将带空格的用户输入路径保存到文本文件。 (赢7)

时间:2013-08-26 07:15:27

标签: input batch-file

首先,我是编程中的菜鸟。 我正在尝试制作一个批处理文件,该文件在第一次运行时将程序的已安装目录作为用户输入(意味着它不应该在第二次运行时询问该目录)。通过搜索各种脚本,我到达这里,

 @echo off
Echo =============================================

echo Directory

Echo =============================================

setlocal enableextensions enabledelayedexpansion

set /p mypath=Please specify install directory; 

Echo %mypath% ----was what you typed

pause

echo start>temp.txt

echo %mypath%>>temp.txt

echo \programfolder\program.exe>>temp.txt

echo -argument -argument>>temp.txt

setlocal enabledelayedexpansion

set FINAL=

for /f %%a in (temp.txt) do (

set FINAL=!FINAL!%%a

)

echo %FINAL%>input.txt

del /q temp.txt

Pause

start "<input.txt"

这会将输入路径保存在“input.txt”文本文件中,并在下次启动时运行该程序。 我希望文本文件的保存路径为“start driveletter:\ foldername \ foldername with spaces \ programfolder \ program.exe”-arguments 但是“start”,“program folder”,“program.exe”和“-arguments”是固定的。 用户输入路径应保存在%mypath%中。

1 个答案:

答案 0 :(得分:0)

我想你做了什么:

@echo off
if exist "go.bat" go.bat
set /p "mypath=Please specify install directory; "
Echo "%mypath%" ----was what you typed
pause
>"go.bat" echo @start "" "%mypath%\programfolder\program.exe" -argument -argument