-1

I'm Ninjight, i'm the same guy that wrote this: creating an self-extracting .exe file with iexpress through command line prompt? this time, i have a problem with an attempted batch extension, so, i made this just for a test, but… it doesn't seem to work i just get "wrong syntax". I'm not good at explaining so i'll end this post like this: "could somebody fix my script and tell me what was wrong? Please?"

    @echo off
    title ex
    setlocal

    if /i [%~1] == [/?] (
For %%t in (
    "This is the command shell for Omega Kernel."
    "Please credit if used elsewhere."
    "commands:"
    ""
    " /g GOTO"
    "   The g command essentially works as CD in CMD."
    ""
    " /d delete directory"
    "   The d command is none other than rd/rmdir in cmd."
    ""
    " /mk MAKE (Directory)"
    "   mk is just a replacement of mkdir/md."
    ""
    " /mv MOVE"
    "   mv Moves something somewhere. that's all folks."
    ""
    " /c COPY"
    "   cp copies something somewhere, letting you add variables"
    ""
    " /va EXPORT FROM VIRTUAL ARCHIVE"
    "   va exports files from the virtual archive of the server."
    "   how does it work? It downloads the virtual archive, unzips it, copies the file and then deletes the archive."
    ""
    " /win Opens CMD."
    ""
    " /update downloads updated tools."
    ""
    ""
    ""
    "Developed by DaviAwesome, 2012"
    ""
    "2018 -Ninjight_"
) do Echo;%%~t
    exit /b
    )


    if /i [%~1] == [/g] (
    set /p input=Where to go? 
    cd %input%
    exit /b
    )

    ::delete folder
    if /i [%~1] == [/d] (
    set /p rminput=What to remove? 
    rd %rminput%
    exit /b
    )

    ::make folder
    if /i [%~1] == [/mk] (
    set /p mkinput=Where? 
    md %mkinput%
    exit /b
    )

    ::move
    if /i [%~1] == [/mv] (
    set /p mvinput=What to move? 
    set /p mvinput2=Where to?
    move %mvinput% %mvinput2%
    exit /b
    )

    ::copy.
    if /i [%~1] == [/c] (
    set /p copyinput0=Copy with?
    set /p copyinput=What to copy? 
    set /p copyinput2=Where to?
    set /p copyinput3=Variables?
    ::if %copyinput0% == xc (
    ::xcopy %copyinput% %copyinput2% %copyinput3%
    ::)

    ::if %copyinput0% == robo (
    ::  robocopy %copyinput% %copyinput2% %copyinput3%
    ::)

    ::if %copyinput0% == robo (
    ::  copy %copyinput% %copyinput2% %copyinput3%
    ::)
    if %copyinput0% == xc goto xc
    if %copyinput0% == c goto c
    if %copyinput0% == robo goto robo

    exit /b
    )

    :xc
    xcopy %copyinput% %copyinput2% %copyinput3%
    exit /b
    )

    :c
    copy %copyinput% %copyinput2% %copyinput3%
    exit /b
    )

    :robo
    robocopy %copyinput% %copyinput2% %copyinput3%
    exit /b
    )

    ::virtual archive
    if /i [%~1] == [/va] (
    set /p archinput=What to export? 
    set /p archinput2=Where to?
    download http://link.suffix/file.extension file.extension
    move file.extension .\folder\
    exit /b
    )

    ::open cmd
    if /i [%~1] == [/win] (
    cmd
    exit /b
    )

    ::update command replaces the old and outdated UP.bat
    if /i [%~1] == [/update] (
    download http://link.suffix/file.extension file.extension
    move file.extension .\tools\folder
    exit /b
    )
Envy
  • 3
  • 5
  • Don't use the double colon for comments inside a parenthesized cod block. – Squashman Sep 06 '18 at 19:14
  • If you remove the `@echo off`, where does the script break? Without looking into it, I'm guessing that a variable doesn't get set somewhere. (Also, use double quotes instead of square brackets for the `if` statements.) – SomethingDark Sep 06 '18 at 19:15
  • You are also defining variables inside a parenthesized code block and then trying to use them in that same block. That requires the use of delayed expansion. – Squashman Sep 06 '18 at 19:20
  • Because you commented out a lot of code you have unbalanced parentheses as well. – Squashman Sep 06 '18 at 19:22
  • Also, you're treating labels like functions, so if you pick /va, /win, or /update, `xcopy` will always run no matter what. – SomethingDark Sep 06 '18 at 19:50
  • @Squashman actually, as you can see in the code, i prepared setlocal, but then forgot to add enabledelayedexpansion. still, thanks for reminding me. and thanks for specifying that i shouldn't have used double colon. – Envy Sep 06 '18 at 20:20
  • @SomethingDark yeah, but HOW do i fix that? – Envy Sep 06 '18 at 20:21
  • Either `goto`s to skip over it or move the copy section to the bottom of the list script. Remember that everything gets read from the top down – SomethingDark Sep 06 '18 at 20:23
  • @SomethingDark hmm…. didn't consider that. Thanks for the tip. Anyway, /mv, /mk and /r are broken too, what should i do? – Envy Sep 06 '18 at 20:40
  • Delayed expansion should definitely have fixed it. I'll have to check when I'm back home. – SomethingDark Sep 06 '18 at 20:42
  • @SomethingDark nope it didn't. – Envy Sep 06 '18 at 20:55

1 Answers1

0
@echo off
title ex
setlocal

if not "%~1" == "/?" goto :endif
    for %%t in (
        "This is the command shell for Omega Kernel."
        "Please credit if used elsewhere."
        "commands:"
        ""
        " /g GOTO"
        "   The g command essentially works as CD in CMD."
        ""
        " /d delete directory"
        "   The d command is none other than rd/rmdir in cmd."
        ""
        " /mk MAKE (Directory)"
        "   mk is just a replacement of mkdir/md."
        ""
        " /mv MOVE"
        "   mv Moves something somewhere. that's all folks."
        ""
        " /c COPY"
        "   cp copies something somewhere, letting you add variables"
        ""
        " /va EXPORT FROM VIRTUAL ARCHIVE"
        "   va exports files from the virtual archive of the server."
        "   how does it work? It downloads the virtual archive, unzips it, copies the file and then deletes the archive."
        ""
        " /win Opens CMD."
        ""
        " /update downloads updated tools."
        ""
        ""
        ""
        "Developed by DaviAwesome, 2012"
        ""
        "2018 -Ninjight_"
    ) do echo;%%~t
    exit /b
:endif

if /i not "%~1" == "/g" goto :endif
    set /p "input=Where to go? "
    cd /d %input%
    exit /b
:endif

::delete folder
if /i not "%~1" == "/d"  goto :endif
    set /p "rminput=What to remove? "
    rd %rminput%
    exit /b
:endif

::make folder
if /i not "%~1" == "/mk" goto :endif
    set /p "mkinput=Where? "
    md %mkinput%
    exit /b
:endif

::move
if /i not "%~1" == "/mv" goto :endif
    set /p "mvinput=What to move? "
    set /p "mvinput2=Where to? "
    move %mvinput% %mvinput2%
    exit /b
:endif

::copy.
if /i not "%~1" == "/c" goto :endif
    set /p "copyinput0=Copy with? "
    set /p "copyinput=What to copy? "
    set /p "copyinput2=Where to? "
    set /p "copyinput3=Variables? "

    if "%copyinput0%" == "xc" (
        xcopy %copyinput% %copyinput2% %copyinput3%
    )

    if "%copyinput0%" == "robo" (
        robocopy %copyinput% %copyinput2% %copyinput3%
    )

    if "%copyinput0%" == "c" (
        copy %copyinput% %copyinput2% %copyinput3%
    )

    exit /b
:endif

::virtual archive
if /i not "%~1" == "/va" goto :endif
    set /p "archinput=What to export? "
    set /p "archinput2=Where to? "
    download http://link.suffix/file.extension file.extension
    move file.extension .\folder\
    exit /b
:endif

::open cmd
if /i not "%~1" == "/win" goto :endif
    cmd
    exit /b
:endif

::update command replaces the old and outdated UP.bat
if /i not "%~1" == "/update" goto :endif
    download http://link.suffix/file.extension file.extension
    move file.extension .\tools\folder
    exit /b
:endif

Enclosures [] changed to "".

Double quoted some strings and variables that may need it.

Negate many if comparisons so as to use goto :endif instead of using parentheses. This allows %variables% to expand without the need for delayed expansion as not enclosed between parentheses.

Removed obsolete labels :xe, :c and :robo as the disabled code is now being used.

michael_heath
  • 5,262
  • 2
  • 12
  • 22
  • i see… well, thank you! in the future i'll try to remeber this, so that i do not do the same mistake again, thanks! – Envy Sep 07 '18 at 08:53
  • You have multiple labels called `:endif`. That's really bad practice in general, although I admit that it works in this particular situation. – SomethingDark Sep 07 '18 at 16:35