Please Read: Significant Update Planned, Migrating Forum Software This Month

See more
See less

Good ol for do loop

  • Filter
  • Time
  • Show
Clear All
new posts

  • Good ol for do loop

    Hi folks!

    So basically I have a .txt file that contains 2 lines. I want to take line 2 of the file and set it as a variable

    I'm typing this in the command prompt to test it out the code, but it's not printing anything out

     For /f "skip=1 %G IN ("file.txt") do @echo %G
    To implement this in my batch file I tried this, but it's a no go

     FOR /f "skip=1" %%G IN ("textfile.txt") do (
    echo %variable%
    it's not printing anything. My prompt is in the same folder s the file (c:\users\user) I'm sure my code is missing something, but not really sure what. If you somebody could point me in the right direction I'd greatly appreciate it

    Line 2 of the text file has no spaces, it's actually the SID of a user profile

  • #2
    Re: Good ol for do loop

    is this what you're trying to do:

    of course, you would have to replace %g with %%g if used in a script.



    • #3
      Re: Good ol for do loop

      Add UseBackQ to the For options, because there are double quotes around the file name.

      "usebackq skip=1"


      This posting is provided "AS IS" with no warranties, and confers no rights.


      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts


      • #4
        Re: Good ol for do loop

        Thank you guys for your replies!

        I actually found a better way to implement what I was trying to do. I work on a helpdesk and rebuilding profiles can take a lot of time. I decided to make a batch file to speed this process up. It took a lot of learning but after a week I was able to get working, and working safely at that. Right now I'm just fixing some things and adding some functionality then eventually I'll pass it on to my colleagues.

        Normally on a call rebuilding a Windows profile can take up to 10 minutes when using the registry editor. My batch file can do it under a minute. It was such a great feeling when I finally got it working.

        I plan on leaning how to use Visual Studio and making an application that does the same thing as the batch file