Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Shell 

Loops

Hello! So I was making a batch file last night, and had a quick thought.
Within the code for a loop
":label
code
code
code
goto label"
It is an infinite loops. But is there a way, or is it even possible to, make the loop happen a certain amount of times? Let's say I want to open three .txt's. I understand I can do "start notepad.exe" three times, but is it at all realistic to make a loop, that opens it once, happen three times, then end?

Thanks to anything helpful.
If I think I'm understanding you correctly, try this :)
Code
@echo off
set/p ?=Enter the path of your textfile (C:\Hello.txt):
set/p $=Enter how many times to open your textfile:
For /L %%Q in (1,1,%$%) do start %?%
@exit

The previous code was with user inputs...but if you want to do it automatically use this one:
Code
@echo off
set ?=C:\FilePath.txt
set $=How many times
For /L %%Q in (1,1,%$%) do start %?%
@exit

Let me know if you need me to explain anything 🤝
Quote:
Code
@echo off
set ?=C:\FilePath.txt
set $=How many times
For /L %%Q in (1,1,%$%) do start %?%
@exit

That's exactly what I'm looking for. Works perfectly. Thank you a bunch!
(Mar 12, 2015 10:37 AM)Deevez Wrote:  That's exactly what I'm looking for. Works perfectly. Thank you a bunch!

Hey no problem. Let me know if you need anything else 🎉
(Mar 12, 2015 10:40 AM)Ventriloquism Wrote:  Hey no problem. Let me know if you need anything else 🎉

There is one thing I guess I could I ask. I've seen this done on a Console App. Now, I say "Console App" because I'm unsure if this was even in Batch or if it was made in VB or something. But this one program, upon the command on "stats", it told you all of your computer's stats, such as: CPU usage, RAM, and stuff like that. Do you by any chance know if that also is possible?
(Mar 12, 2015 11:23 AM)Deevez Wrote:  There is one thing I guess I could I ask. I've seen this done on a Console App. Now, I say "Console App" because I'm unsure if this was even in Batch or if it was made in VB or something. But this one program, upon the command on "stats", it told you all of your computer's stats, such as: CPU usage, RAM, and stuff like that. Do you by any chance know if that also is possible?

You might be looking for WMIC. Open command prompt and type in
Code
wmic /?

That might help you get started.
Quote:
Code
wmic /?

That might help you get started.

I'll definitely try this out. Thanks a bunch!
Yeah agreed. This looks like a job for WMIC
That helped a lot. Thanks a lot guys!
Another method of looping:

Code
@echo off
set num=0
:label
set /a num+=1
echo Cats
echo are
echo best
echo %num%
if not %num% == 5 goto :label
pause

Also since nobody fully explained the wmic approach, the following commands are useful:

Code
wmic baseboard list brief
wmic memorychip list brief
wmic memphysical list brief
wmic cpu list brief
wmic bios list brief
wmic diskdrive list brief
wmic logicaldisk list brief

More types of information are available. wmic /? will show you all the different things that are available. Basically all the CAPS names, that don't start with a forward slash (/).
Always here to explain things for people, Annikk. Haha, thanks!


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by n00b.caApr 4, 2020 12:39 PM 3 200 Apr 4, 2020 12:39 PM
Last Post: n00b.ca
[Java] by YukinoNov 12, 2019 05:50 PM 6 425 Nov 12, 2019 05:50 PM
Last Post: Accord
[C] by GoddessTaliyahMay 3, 2018 02:22 PM 4 393 May 3, 2018 02:22 PM
Last Post: 0xDEAD10CC