//File Lister Version 1.0
// By DreamVB

#include <iostream>
#include <Windows.h>

using namespace std;
using std::cout;
using std::endl;

int main(int argc, char *argv[]){
	HANDLE f = 0;
	WIN32_FIND_DATAA wfd;

	char *PathName = NULL;
	char lzPath[128];
	int pos = -1;
	int x = 0;

	if (argc != 2){
		cout << "Usage: <Folder>" << endl;
		exit(1);
	}

	strcpy(lzPath, argv[1]);
	//Convert char to wchar

	PathName = new char[strlen(lzPath) + 1];
	strcpy(PathName, lzPath);

	//Find last backslash
	for (x = 0; x < strlen(PathName); x++){
		if (PathName[x] == '\\'){
			pos = x;
		}
	}

	if (pos != -1){
		PathName[pos + 1] = '\0';
		//Output path
		cout << "Folder Listing For " << PathName << endl << endl;
	}
	else{
		cout << "Folder Listing For \\" << endl << endl;
	}

	//Get first file.
	f = FindFirstFileA(lzPath, &wfd);
	
	//Check for inaild path.
	if (f == INVALID_HANDLE_VALUE){
		cout << "Folder or files not found." << endl << lzPath << endl;
		exit(1);
	}

	//Gets the list of files
	while (FindNextFileA(f, &wfd) != false){
		if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
			//Left for folders
		}
		else{
			//Output filename.
			cout << wfd.cFileName << endl;
		}
	}

	//Clear up.
	memset(lzPath, 0, sizeof(lzPath));
	delete[]PathName;

	//Close file
	FindClose(f);

	return 0;
}