Good ol for do loop
Home › Forums › Scripting › DOS Command Shell › Good ol for do loop
This topic contains 3 replies, has 4 voices, and was last updated by MR_Aguilera 5 years, 1 month ago.
-
AuthorPosts
-
October 6, 2014 at 6:28 am #164353
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
[/CODE] To implement this in my batch file I tried this, but it’s a no go[CODE]
FOR /f “skip=1” %%G IN (“textfile.txt”) do (
%%G=%variable%
echo %variable%
)
[/CODE]
it’s not printing anything. My prompt is in the same folder s the file (c:users[I]user[/I]) 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 itEdit:
Line 2 of the text file has no spaces, it’s actually the SID of a user profile[CODE]
For /f “skip=1 %G IN (“file.txt”) do @echo %G
[/CODE] To implement this in my batch file I tried this, but it’s a no goFOR /f “skip=1” %%G IN (“textfile.txt”) do (
%%G=%variable%
echo %variable%
)
[/CODE]
it’s not printing anything. My prompt is in the same folder s the file (c:users[I]user[/I]) 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 itEdit:
Line 2 of the text file has no spaces, it’s actually the SID of a user profile[CODE]
FOR /f “skip=1” %%G IN (“textfile.txt”) do (
%%G=%variable%
echo %variable%
)
[/CODE]
it’s not printing anything. My prompt is in the same folder s the file (c:usersuser) 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 itEdit:
Line 2 of the text file has no spaces, it’s actually the SID of a user profileOctober 9, 2014 at 9:04 am #390377Re: 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.
-Ricc
October 11, 2014 at 3:33 pm #228452Re: Good ol for do loop
Add UseBackQ to the For options, because there are double quotes around the file name.
“usebackq skip=1”
/Rems
October 15, 2014 at 5:57 am #390370Re: 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
-
AuthorPosts
You must be logged in to reply to this topic.