Help!!!

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Bulleyeaccuracy
Posts: 6
Joined: 06 Jul 2012 10:40

Help!!!

#1 Post by Bulleyeaccuracy » 06 Jul 2012 10:47

ok so i am making this program that backs up minecraft saved levels, there is more to it and it is really time consuming to make. Anyway, on the main menu screen it asks you to type in the name of your world and it works fine, but if your world has a space in it then the program just closes. I know a way to get around this but it would take a lot of coding (well not that much, but still) and the program would not look as good.

so over all i need to know how to make a batch program that you can have an input that has 2 words that are parted with a space .

i really really hope someone can help :D 8)

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Help!!!

#2 Post by Ed Dyreen » 06 Jul 2012 11:01

Bulleyeaccuracy wrote:so over all i need to know how to make a batch program that you can have an input that has 2 words that are parted with a space .
I don't see a problem here...

Code: Select all

>set /p ?=
hel lo

>set ?
?=hel lo

>
Can you post your code and how you use it that makes it fail, don't have my crystal ball handy :)

Bulleyeaccuracy
Posts: 6
Joined: 06 Jul 2012 10:40

Re: Help!!!

#3 Post by Bulleyeaccuracy » 06 Jul 2012 11:16

Code: Select all

:minecraftmainmenu
@echo off
title Minecraft World Saver
color 0A
cls
dir C:\Users\Michael\AppData\Roaming\.minecraft\saves /b
echo Please type in the name of the world which you would like to back up
echo or type "all" to back up all
set /p minecraftsaver=World name:
if %minecraftsaver%==all goto minecraftall else goto minecraftbackuperror


that is just the menu part (i know i do it the loops the bad way, but that is how i first started learning batch programing and i am going to add this to my bigish program and i would have to like recode the hole thing if i were to swap it to the real loops).

so if i had 2 minecraft worlds and one was named "moo" and the other was named "moo cow"...

if i were to type in moo then the program would works fine and goes to the next part of the code. but if i were to type in moo cow it would not work because there is a space between "moo" and "cow".

i am not %100 sure what is happening but i have tried it on many different minecraft worlds and every world without a space works fine and the ones with the space just closes the program.

anyways it is early in the morning where i live and i have not gotten any sleep so i am going to go to bed now, i will see if someone has a solution for me when i get up ;)

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Help!!!

#4 Post by Squashman » 06 Jul 2012 13:59

Code: Select all

if %minecraftsaver%==all goto minecraftall else goto minecraftbackuperror

Did you happen to read the help file for the IF command.

Code: Select all

H:\>if /?
Performs conditional processing in batch programs.

IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command

  NOT               Specifies that Windows XP should carry out
                    the command only if the condition is false.

  ERRORLEVEL number Specifies a true condition if the last program run
                    returned an exit code equal to or greater than the number
                    specified.

  string1==string2  Specifies a true condition if the specified text strings
                    match.

  EXIST filename    Specifies a true condition if the specified filename
                    exists.

  command           Specifies the command to carry out if the condition is
                    met.  Command can be followed by ELSE command which
                    will execute the command after the ELSE keyword if the
                    specified condition is FALSE

The ELSE clause must occur on the same line as the command after the IF.  For
example:

    IF EXIST filename. (
        del filename.
    ) ELSE (
        echo filename. missing.
    )

The following would NOT work because the del command needs to be terminated
by a newline:

    IF EXIST filename. del filename. ELSE echo filename. missing

Nor would the following work, since the ELSE command must be on the same line
as the end of the IF command:

    IF EXIST filename. del filename.
    ELSE echo filename. missing

The following would work if you want it all on one line:

    IF EXIST filename. (del filename.) ELSE echo filename. missing

Bulleyeaccuracy
Posts: 6
Joined: 06 Jul 2012 10:40

Re: Help!!!

#5 Post by Bulleyeaccuracy » 06 Jul 2012 18:33

i guess i could say i am ok at batch coding, but i have no idea what you ment by giving me the help for the if command.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Help!!!

#6 Post by Fawers » 06 Jul 2012 20:08

Try this

Code: Select all

if /i "%minecraftsaver%" == "all" (goto minecraftall) else goto minecraftbackuperror

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Help!!!

#7 Post by Fawers » 06 Jul 2012 20:13

Bulleyeaccuracy wrote:i guess i could say i am ok at batch coding, but i have no idea what you ment by giving me the help for the if command.

What he meant was probably referring to that line of code: if %minecraftsaver%==all goto minecraftall else goto minecraftbackuperror, and this part on the help: IF EXIST filename. (del filename.) ELSE echo filename. missing.
If you want the IF statement on one single line, you have to enclose the command [before the ELSE satement] in (brackets).

Bulleyeaccuracy
Posts: 6
Joined: 06 Jul 2012 10:40

Re: Help!!!

#8 Post by Bulleyeaccuracy » 06 Jul 2012 20:55

if you mean for me to do this...

Code: Select all

if %minecraftsaver%==all goto minecraftall (else goto minecraftbackup1)


it does not work (well it works, but gives me the same problem). and i have tried putting it in 2 lines and it does also not work.

besides, if that was my problem when would it work on the words without spaces? so i am 99% sure that it has nothing to do with the if statement.

but then again you guys are probably 5000 times better then me ;)

but if you don't mind could you please code that section for me if you think you know how to do it? because i honestly don't think batch programming allows to have 2 words in an input.

and if you guys can't work it out i will just do something else that will make the program look worse but it will make it work ;)


(btw i changed the code slightly so that is why it says "minecraftbackup1" instead of "minecraftbackuperror")

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help!!!

#9 Post by foxidrive » 06 Jul 2012 22:27

Code: Select all

if /i "%minecraftsaver%"=="all" (goto :minecraftall) else (goto :minecraftbackuperror)


The double quotes in the comparison gather up the two words into one term.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Help!!!

#10 Post by Fawers » 07 Jul 2012 17:21

Bulleyeaccuracy,
no.
The brackets enclose the command(s) after the IF condition and before the ELSE.
e.g.

Code: Select all

if %minecraftsaver%==all (goto minecraftall) else goto minecraftbackup1

Also, I answered what will probably solve your problem on my first post.
Fawers wrote:Try this

Code: Select all

if /i "%minecraftsaver%" == "all" (goto minecraftall) else goto minecraftbackuperror

You can solve general spacing problems with double quotes. :)

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Help!!!

#11 Post by Squashman » 08 Jul 2012 08:45

Bulleyeaccuracy wrote:if you mean for me to do this...

Code: Select all

if %minecraftsaver%==all goto minecraftall (else goto minecraftbackup1)


How did you come up with that after I showed you the help file which explained how to use IF ELSE and Fawers gave you the correct syntax for using an IF ELSE with your code.

Bulleyeaccuracy
Posts: 6
Joined: 06 Jul 2012 10:40

Re: Help!!!

#12 Post by Bulleyeaccuracy » 11 Jul 2012 01:00

Squashman wrote:
Bulleyeaccuracy wrote:if you mean for me to do this...

Code: Select all

if %minecraftsaver%==all goto minecraftall (else goto minecraftbackup1)


How did you come up with that after I showed you the help file which explained how to use IF ELSE and Fawers gave you the correct syntax for using an IF ELSE with your code.


sorry i have not posted for a while, my homes electricity has been screwing up but it is fine now ;)

i have recoded the program to get rid of the else statment and it still does not work (if you bothered to read the histroy you would have seen that :P). So it has nothing to do with the if statment!!

i am 99% sure that you can't have 2 words in the same input

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Help!!!

#13 Post by Ed Dyreen » 11 Jul 2012 01:48

Bulleyeaccuracy wrote:i am 99% sure that you can't have 2 words in the same input
Unless these 2 words are larger than 8192-10 bytes, you are wrong, didn't you see my previous example ?

Looks to me you are trying to 'jump' or even better 'call' labels based upon input and are hard-coding the calls using if statements.
A possibly more suited solution that doesn't requires hard-coding is using the input itself as the data for the call.

Code: Select all

@echo off &setlocal enableDelayedExpansion

:init ( null )
:: (
       title Minecraft World Saver &color 0A &cls

       set /a $err = 0

       call :main %*

       echo.Is this what u wanted ?
       pause
:: )
exit /b %$err%

:main ( paramRAW,# )
:: (
       dir /b "C:\Users\Michael\AppData\Roaming\.minecraft\saves"

       echo.Please type in the name of the world which you would like to back up
       echo.or type "all" to back up all.

       set /p "$=World name:" &2>nul ( call :minecraft!$! "()" ) ||call :minecraftbackuperror !$!

       set /a $err = !errorLevel!
:: )
exit /b %$err%

:minecraftall ( null )
:: (
       echo.Don't type 'all' please, I don't like this :@
:: )
exit /b %$err%

:minecraftbackuperror ( %1,# )
:: (
       echo.Why did you type '%~1', type 'all' please, I don't like this :@
:: )
exit /b 1

Code: Select all

Please type in the name of the world which you would like to back up
or type "all" to back up all.
World name:all
Don't type 'all' please, I don't like this :@
Is this what u wanted ?
Druk op een toets om door te gaan. . .

Code: Select all

Please type in the name of the world which you would like to back up
or type "all" to back up all.
World name:whoopTiddy
Why did you type 'whoopTiddy', type 'all' please, I don't like this :@
Is this what u wanted ?
Druk op een toets om door te gaan. . .

Hope it helps,

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Help!!!

#14 Post by Squashman » 11 Jul 2012 05:59

Bulleyeaccuracy wrote:i have recoded the program to get rid of the else statment and it still does not work (if you bothered to read the histroy you would have seen that :P). So it has nothing to do with the if statment!!

I don't see any of your posts saying anything to that affect. If you could show me which one it is I would be more than happy to look at it.

Bulleyeaccuracy
Posts: 6
Joined: 06 Jul 2012 10:40

Re: Help!!!

#15 Post by Bulleyeaccuracy » 11 Jul 2012 21:05

Squashman wrote:
Bulleyeaccuracy wrote:i have recoded the program to get rid of the else statment and it still does not work (if you bothered to read the histroy you would have seen that :P). So it has nothing to do with the if statment!!

I don't see any of your posts saying anything to that affect. If you could show me which one it is I would be more than happy to look at it.


when you look up i said "it does not work (well it works, but gives me the same problem). and i have tried putting it in 2 lines and it does also not work."

i implied that i got rid of the else statment, sorry i guess i was not clear :(

Post Reply