It only takes a minute to sign up. Connect and share knowledge within a single location that is structured and easy to search. I need to run a windows command n times within a bat script file. I know how to do this in various programming languages but cannot manage to get it right on the windows command line I can write a program in java, perl, c or whatever that will generate a bat script that looks like this.
But the thing is that I need a concise way to specify a range of numbers to iterate through within the script. Good article here and XP specifics here. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Learn more. For Loop counting from 1 to n in a windows bat script Ask Question. Asked 12 years, 4 months ago. Active 7 years, 2 months ago. Viewed k times. Unlock 1 Answer and 4 Comments. Andrew Hancock - VMware vExpert.
See if this solution works for you by signing up for a 7 day free trial. What do I get with a subscription? With your subscription - you'll gain access to our exclusive IT community of thousands of IT pros. We can't always guarantee that the perfect solution to your specific problem will be waiting for you.
If you ask your own question - our Certified Experts will team up with you to help you get the answers you need. Who are the certified experts? How quickly will I get my solution? We can't guarantee quick solutions - Experts Exchange isn't a help desk. We're a community of IT professionals committed to sharing knowledge. I didn't say he was wrong.
I was agreeng that PowerShell can do this much more easily. That's a common mistake. Remember that the Powershell pipeline will "unroll" an array into individual elements. When you did this:. The pipeline peeled the first element of the array off and did a get-member on it, and gave you the result, and you got all the properties and methods of a string object.
To see the members of the array itself, you need to do a get-member on it directly, not through the pipeline:. Edit: jv, How did you know to use. If I pipe gc test. Well I dereferenced the results with teh dot operator.
Yes, in POwerShell, the dot is an operator. It is also a very much overloaded operator. This get a file as a collection of lines with no variable that is visible. This is called an 'anonymous' variable. The variable is still created but it is not dsiplayed and it will not be sent to the console because I have asked to to be acted on by teh dot operato to give me only the count of items.
It is a very good short hand and makes code more compact, readable and usable. We do it in C all of the time. NET, they didn't lend to doing this. VB code rends to get big and clunky. So mj. Yes you cannot inspect aa file name.
Even if you do this you will not find count. Because the count property is an alias for array lenght anda few other object collections. As MJ points up. Jsut doing GM on the file result gers only the first element of [string[]] string array.
I answered the question that was asked, after it appeared that it was going to go unanswered. No, no,. I also thought jv wasn't going to answer me, I thought he'd missed that.
His explanation gave me further insight into the workings of the dot operator, and I thank him for that too. You both have very different styles of answering questions, and I have got used to jv, he doesn't pull punches, but he is very helpful too when he wants to be. I am not offended in any way, and I don't think you should be either. Please lighten up, guys. There's nothing wrong with healthy positive debate.
This is exactly the enviroment that Jerry Weinberg's idea of "Egoless Programming" was intended to be applied to. That idea has proven itself over and over again in the last 40 years, and to the degree that it is ignored, the forums will eventually suffer.
We got on fine until one day you lit into me about "how much I don't know". I have never directed a personal attack or remark against you. If I have had any disagreement with you "since the day you got here". This thread has been a thrilling ride from "How to count lines in a text file" to what really set things alight, which was jv's statement:. I think the teasing of me was in some way a catalyst for a smouldering thing which has nothing to do with me or coding or positive healthy debate.
0コメント