Answered Reading lines from a text file in batch

  • 15. května 2012 7:12
     
      Obsahuje kód

    hey guys, im a batch enthusiast and i have had my experiences in batch, like i made tic-tac-toe from scratch, but this one really puzzles me.

    im trying to make a login thing, because im really just an enthusiast and i like making stuff and showing my friends

    and im been searching and you have to use the 'for' command, yeeeaaahhh well, that doesn't work for me, and i don't know why :'_(

    this is what i have

    @echo off
    :start
    cls
    echo. 
    echo login thing
    echo.
    echo 1)create account
    echo 2)login
    echo.
    set /p log=
    if %log% equ 1 goto create
    if %log% equ 2 goto Login
    if %log% gtr 2 echo Thats an invalid choice.
    :create
    cls
    echo.
    echo create account
    echo.
    set /p UN=Username:
    set /p PW=Password:
    echo.%UN%> "C:\Users\[Computer]\Desktop\Stuff\New folder\Login.txt"
    echo.%PW%>> "C:\Users\[Computer]\Desktop\Stuff\New folder\Login.txt"
    echo.
    PAUSE
    goto start
    :Login
    cls
    set confirm=0
    echo.
    echo LOGIN
    echo.
    set /p UNL=Username:
    set /p PWL=Password:
    for /f %%a in (Login.txt) do set UNLC=%%a
    echo %UNLC%
    pause
    if %confirm% equ 2 goto GRANTED
    if not %confirm% equ 2 goto DENIED
    :GRANTED
    cls
    echo.
    echo ACCESS GRANTED
    echo.
    PAUSE
    exit
    :DENIED
    cls
    echo.
    echo ACCESS DENIED
    echo.
    echo Press any key to retry
    echo.
    Pause >nul
    goto Login
    
    

    im trying to get it so that it reads the first 2 lines from the text file, which has the username and password, so that if it doesn't match up..... access denied, etc, but for me it doesn't work, i may be 13 but im quite smart, i didn't think i would need to make a thread on a forum, but none of the ones i have gone to have worked for me, what happens is it always reads the second line :( and i don't know why, the for command doesn't work for me, and nothing i add to the command will make it work, im wondering if someone can change my code a bit so i can understand it, and so it works and also why can't you have the full file location the brackets ie. for /F %%a in ("C:\bla\bla\bla") do bla bla bla. is says the file cannot be found, wtf. :( so im saddened by the fact that my thing won't work and that i have to go and make a thread for something that is really easy, to others, but for me, reading something out of a text file on batch, is harder than you think. :(please help me, abd if you have to change the ENTIRE code if i have also done something wrong, I've also changed my computer name and taken some parts of the code out (took them out a while ago). so please if you can help me, i would HIGHLY appreciate it, thanks :D 

    also i have Acer Aspire 5750, 64bit, Windows 7 Service Pack 1.

    MrSqwiggles ;)

Všechny reakce