Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » FindFile, get dir list
FindFile, get dir list [message #18513] Mon, 06 October 2008 05:12 Go to next message
amando1957 is currently offline  amando1957
Messages: 57
Registered: November 2007
Location: Wien/Vienna/Viden
Member
Hi to all,

I've tried to get the list of "D:/111/" this way:
#include <Core/Core.h>
using namespace Upp;

CONSOLE_APP_MAIN
{
	FindFile fifi("D:/111/");
	Vector<String> dirs, files;
	String name;
	
	while (fifi.Next())
	{
		name = fifi.GetName();
		if (fifi.IsDirectory()) dirs << name;
		else                    files << name;
	}
	
	int i;
	Cout() << "=====>> list of dirs:" << '\n';
	for (i=0; i < dirs.GetCount(); i++)
		Cout() << dirs[i] << '\n';
	
	Cout() << "=====>> now the files:" << '\n';
	for (i=0; i < files.GetCount(); i++)
		Cout() << files[i] << '\n';
	
	system("pause");
}

what did not work. Anything wrong here?

Martin
Re: FindFile, get dir list [message #18514 is a reply to message #18513] Mon, 06 October 2008 07:58 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
CONSOLE_APP_MAIN
{
	FindFile fifi("D:/111/*.*");
	Vector<String> dirs, files;
	String name;
	
	while (fifi)
	{
		name = fifi.GetName();
		if (fifi.IsDirectory()) dirs << name;
		else                    files << name;
                fifi.Next();
	}

Re: FindFile, get dir list [message #18524 is a reply to message #18514] Mon, 06 October 2008 21:13 Go to previous messageGo to next message
amando1957 is currently offline  amando1957
Messages: 57
Registered: November 2007
Location: Wien/Vienna/Viden
Member
Thank you, Embarassed, could have known myself...
That's working now, Smile.

BTW, the names "." and ".." are still delivered, though they are being handled in "path.cpp":
bool FindFile::IsFolder() const {
	if(a)
		return IsDirectory()
			&& !(a->cFileName[0] == '.' && a->cFileName[1] == 0)
			&& !(a->cFileName[0] == '.' && a->cFileName[1] == '.' && a->cFileName[2] == 0);

with 2008.1 at WIN2K.

Maybe the filter ist better made here
bool FindFile::Next()
{
	if(!FindNextFile(handle, a)) {
		Close();
		return false;
	}
	
	while ((a->cFileName[0] == '.' && a->cFileName[1] == 0)
		|| (a->cFileName[0] == '.' && a->cFileName[1] == '.' && a->cFileName[2] == 0)
		)
		{
		Next();
		}

	return true;
}


Martin
Re: FindFile, get dir list [message #18538 is a reply to message #18524] Tue, 07 October 2008 12:33 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Use IsFolder to ignore . / ..

. / .. are included based on belief that in some very specific cases, you expect them in the list as it is "standard behaviour".

Mirek

[Updated on: Tue, 07 October 2008 12:34]

Report message to a moderator

Previous Topic: How to subtract some days/months to a date variable?
Next Topic: Xmlize works only for storing
Goto Forum:
  


Current Time: Sat Apr 20 10:31:57 CEST 2024

Total time taken to generate the page: 0.05114 seconds