Solved

Batch Problems - MODE & Enum Loop

Posted on 2009-06-27
4
328 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

840 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