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 » Developing U++ » UppHub » DirectoryCreateMulti as an alternative for RealizeDirectory
DirectoryCreateMulti as an alternative for RealizeDirectory [message #19484] Sun, 07 December 2008 20:15 Go to previous message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
In the "Core\Path.h" file we have useful function RealizeDirectory that creates not existent directories from the given path. I create alternative function with name DirectoryCreateMulti. Complexity: recursion versus memory management with Vector.

#ifdef PLATFORM_POSIX
bool DirectoryCreateMulti(const String& path, int mode = 0755)
#else
bool DirectoryCreateMulti(const String& path)
#endif
{
	Vector<String> dirs;
	
	for (int i=path.GetCount() - 1; ; --i)
	{
		i = path.ReverseFind(DIR_SEP, i);
#ifdef PLATFORM_POSIX
		if (i>0)
#else
		if (i>0 && path[i - 1] != ':')
#endif
		{
			const String tmp(path.Left(i));
			if (!DirectoryExists(tmp))
			{
				dirs.Add(tmp);
			}
			else break;
		}
		else break;
	}
	
	for (int i=dirs.GetCount() - 1; i>=0; --i)
	{
#ifdef PLATFORM_POSIX
		if (!DirectoryCreate(dirs[i], mode))
#else
		if (!DirectoryCreate(dirs[i]))
#endif
		{
			return false;
		}
	}
#ifdef PLATFORM_POSIX
	return DirectoryCreate(path, mode);
#else
	return DirectoryCreate(path);
#endif
}

[Updated on: Sun, 07 December 2008 21:34]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Added Signals package
Next Topic: Cairo
Goto Forum:
  


Current Time: Sun Apr 28 09:43:24 CEST 2024

Total time taken to generate the page: 0.01866 seconds