Solved

Batch Problems - MODE & Enum Loop

Posted on 2009-06-27
4
321 Views
Last Modified: 2012-05-07
I am creating a batch file that had MODE working at one point, but upon addition of some lines, it stopped working. I removed the added lines, it still did not work yet. Will also not work in any other BATCH file i make. Works however in a command prompt environment. The code for the MODE command is:

MODE CON COLS=55 LINES=28


I am also having issues with an enumeration listing of files in a directory, I use a FOR to add 1 to a enumeration variable and attempt to echo the number without the file name attached to it, it will simply say "1" and then go to the next file, it will not add but it will go back to just showing "1", with a single line of output being "11111111111111" or so. The variable after it is set i checked and it is set to 1, til i run the code again, it will than be incremented once more. I gave up on this code and am requesting perhaps someone knows a better way to enumerate the list out in a format such as

# - FOLDER NAME

1 - a
2 - b
3 - c
4 - d
5 - e
0
Comment
Question by:meepee
  • 3
4 Comments
 
LVL 21

Accepted Solution

by:
AmazingTech earned 100 total points
ID: 24730099
The mode command should work. I'm not too sure what the problem you're having with it.

Here's a simple way to get the numbering of the folders.
@Echo Off

SETLOCAL ENABLEDELAYEDEXPANSION

set folder=1

for /f "tokens=*" %%a in ('dir /ad /b') do (

    echo !folder!,%%a

    Set /a folder+=1

)

Open in new window

0
 

Author Comment

by:meepee
ID: 24730225
im having issues with some similar commands, such as IPCONFIG -- however if i change directory to %SystemRoot%\system32\, it seems to pick it up just fine (and it still works when i go to change directory afterwards) but when reloaded the cmd prompt, it will go back to saying it cant be found. I just did a fresh install of windows about a week ago. Doubt it could be file corruption this early since i hadnt installed anything new that i didnt use before and that happened a few days after i got all of it on here. I reset my PATH variable and that did not help at all on that matter.

As for your batch code, it is acceptable, it works to the way i need it to, not sure why i was unable to do that successfully before.
0
 

Author Comment

by:meepee
ID: 24730258
Nevermind, i have figured out the problem concerning the not recognizing of any commands - i forgot that there were two sets of PATH variables, the global one was set correctly, but at some point the local PATH variable (which overrides global if present) was set incorrectly. It appears to have been set to my Visual Studio 6.0 C++ bin folder. Which has never happened to me before. I award full points to you AmazingTech
0
 

Author Closing Comment

by:meepee
ID: 31597610
I thank you for the time you provided me.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now