Solved

Batch Problems - MODE & Enum Loop

Posted on 2009-06-27
4
318 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I thank you for the time you provided me.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

6 Experts available now in Live!

Get 1:1 Help Now