有人可以帮助我修复此批处理文件吗?

时间:2020-05-18 11:23:35

标签: batch-file

我想制作一个记事本程序,但文本文件的创建者无法使用。有人能帮我吗?我需要在发布之前添加更多详细信息,因此请忽略此处的所有内容(代码除外)。

IF [%writeone%]==[] (
    set /p writeone= Name:
    cls
    echo Ok, your file has been created. Have fun!
    pause
    cls
    set /p textone=
    pause
    echo Ok, now your done, you will be redirected to the desktop...
    pause
    goto desktop
) ELSE (
    IF [%writetwo%]==[] (
        set /p writetwo= Name:
        cls
        echo Ok, your file has been created. Have fun!
        pause
        cls
        set /p texttwo=
        pause
        echo Ok, now your done, you will be redirected to the desktop...
        pause
        goto desktop
    )
) ELSE (
    IF [%writethree%]==[] (
        set /p writethree= Name:
        cls
        echo Ok, your file has been created. Have fun!
        pause
        cls
        set /p textthree=
        pause
        echo Ok, now your done, you will be redirected to the desktop...
        pause
        goto desktop
    )
)

Lorem ipsum dolor坐着,sectecturur熟识精英,sed do eiusmod tempor indicidunt ut Labore et dolore magna aliqua。尽量不要抽烟,不要因抽烟而锻炼。 Duis aute irure dolor in reprehenderit in voltate velit esse cillum dolore eu fugiat nulla pariatur。不愿发生的圣人occaecat cupidatat事故,在犯有刑事责任的动议中被取消

2 个答案:

答案 0 :(得分:1)

好吧,很奇怪,我们将需要更多信息。 据我所知,您没有写任何文件。 最简单的方法:

echo test > filename.extension

要创建一个名为filename.extension的文件,其中包含单词“ test”。

您可以使用echo %variable% > file

将变量写入文件中。

没有更多信息,恐怕很难提供帮助。

答案 1 :(得分:0)

如果要缩进打开的块,您的代码将更易于阅读和调试。完成后,您应该清楚地看到自己处于else条件而没有匹配的if或右括号未正确放置的情况。根据您的代码,我的经验告诉我是后者。

If "%writeone%" == "" (
    Set /P "writeone=Name: "
    ClS
    Echo Ok, your file has been created. Have fun!
    Pause
    ClS
    Set /P "textone="
    Pause
    Echo Ok, now your done, you will be redirected to the desktop...
    Pause
    GoTo desktop
) Else (
    If "%writetwo%" == "" (
        Set /P "writetwo=Name: "
        ClS
        Echo Ok, your file has been created. Have fun!
        Pause
        ClS
        Set /P "texttwo="
        Pause
        Echo Ok, now your done, you will be redirected to the desktop...
        Pause
        GoTo desktop
    ) Else (
        If "%writethree%" == "" (
            Set /P "writethree=Name: "
            ClS
            Echo Ok, your file has been created. Have fun!
            Pause
            ClS
            Set /P "textthree="
            Pause
            Echo Ok, now your done, you will be redirected to the desktop...
            Pause
            GoTo desktop
        )
    )
)

还请注意,我已经用IF [%variable%]==[]替换了您的实施不佳的If "%variable%" == "",并在您的set /p命令周围加上了保护性双引号。此外,值得一提的是,您似乎在请求输入,而没有提示最终用户输入您想要他们输入的内容,以定义名为textonetexttwo和{{1}的变量},建议您像对textthreewriteonewritetwo的示例一样进行修改。


但是,我不确定您是否真的需要writethree条件。以下可能是您所需要的:

else