display | more...

Here is a nifty little program that I made, originally to allow my dad to print out lists of courses he had installed for a golf game.

To prepare the file that the program uses, you need to use a trick you can find at PCWorld.com that I've modified a bit so that it saves the directory listing to a file, instead of printing it.

You can find the instructions at http://www.pcworld.com/howto/article/0,aid,14312,00.asp, and all you need to do is remove the "/p" in the "notepad /p c:\contents.fil" line of the .bat file.

The file that is made is just like what you get in DOS when you type "dir". This can be unsightly, especially if you only want a few extensions to show, and/or want it alphabetized. This program cleans it up.

Once you have the file made, compile the following source code, and put the executable in the same directory as the file (unless you specify the directory of the file within the code). Feel free to make any changes to the code you want, except for the line giving me credit.



#include 
#include 
#include "apstring.h"
#include "apvector.h"
#include <conio.h>

void anykey();

void main()
{
	cout << "Make sure that the current listing of courses is in file courselist.txt\n";
	cout << "The new list of courses is in file newcourselist.txt\n";
	// variables named dad_ because I wrote this for my dad
	ifstream dads("courselist.txt"); // where we're getting the information from
	ofstream dadt("newcourselist.txt"); // where we're putting it to
	char crnt=' ';
	apstring crs;
	int lines=0;
	int cnt;
	apvector <apstring> file(1);

	while (!dads.eof())
	{
		cnt=0;
		crnt=' ';
		while(crnt!=':'&&!dads.eof())
		{
			if(!dads.eof())
				crnt = (char) dads.get();
		}
		for(int i=0; i<4; i++)
		{
			if(!dads.eof())
				crnt = (char) dads.get();
		}
		int count=0;
		while(crnt!='\n'&&!dads.eof())
		{
			if(dads.good())
			{
				if(count==0)
				{
					if(!dads.eof())
						crnt = (char) dads.get();
					if(crnt>96&&crnt<123)
						crnt -= 32;
					crs = crnt;
					count++;
				}
				if(count>0)
				{
					if(!dads.eof())
						crnt = (char) dads.get();
					crs += crnt;
				}
			}
		}
		file[file.length()-1]=crs;
		file.resize(file.length()+1);
	}

	apstring tmp;
	apstring trash;

	for (int i=0; i<file.length()-1; i++)
	{
		for (int j=0; j<file.length()-1-i; j++)
			if (file[j+1] < file[j])
			{
				tmp = file[j];
				file[j] = file[j+1];
				file[j+1] = tmp;
			}
	}
	int good;
	for(int a=0; a<file.length()-1; a++)
	{
		good=0;
		for(int b=0; b < file[a].length()-3; b++)
		{
			trash=file[a];
			// Here is where you put the file extension you're looking
			// for.  It was designed to look for .crs files.  If you
			// Want something else, just trade these characters for
			// your file extension:
			//            #                #                #
			if(trash[b]=='c'&&trash[b+1]=='r'&&trash[b+2]=='s')
				good=1;
			// copy the past two lines as many times as you want
			// to allow for multiple extensions to show (for
			// example, if you want .gif and .jpg
		}
		if(good==1)
			dadt <&<& file[a];
	}
	dads.close();
	dadt.close();
	cout << "\nSort is done.  Program made by Dan (Eternal Shroud).\n";
	anykey();
}

// hey hey hey!  It's my anykey function!  (modify it if you aren't using
// MSVC++.  That prog makes it wacky, so I had to add the "cout << endl")
void anykey()
{
	cout << endl;
	getch();
}


Ok, I put comments in so you can edit it to fit your needs. Beyond that, just look at it to figure out how it works.

Log in or register to write something here or to contact authors.