Ejemplo n.º 1
0
/*
 bool KDirectory::isDirEmpty( const KData& fullDir )
 {
 KData dtDir = fullDir;
 dtDir.makePath( true );
 DIR* dir;
 if ( (dir=opendir(dtDir.getData())) == NULL )
 return false;
 struct dirent *pDirent;
 while( ( pDirent = readdir(dir) ) != NULL  )
 {
 struct stat statbuf;
 KData dtPath = dtDir;
 dtPath += pDirent->d_name;
 if ( stat(dtPath.getData(),&statbuf) == -1 )
 continue;
 if ( S_ISDIR(statbuf.st_mode) )
 {
 if ( pDirent->d_name && strcmp(pDirent->d_name,".") && strcmp(pDirent->d_name,"..") )
 {
 if ( !isDirEmpty(dtPath) )
 {
 closedir( dir );
 return false;
 }
 }
 }
 else
 {
 closedir( dir );
 return false;
 }
 }
 closedir( dir );
 return true;

 }
 */
bool KDirectory::open(const KData& directory, bool create)
{
	if (directory.isEmpty())
	{
		return false;
	}

	KData dir = directory;
	int pos;
	KData dtKData = "\\";
	while ((pos = dir.find(dtKData)) != -1)
	{
		dir.replace(pos, 1, "/");
	}
	_directory.erase();

	bool bDirExist = isDirectoryExist(dir);
	if (!bDirExist)
	{
		if (create)
		{
			if (!createDir(dir))
				return false;
		}
		else
		{
			return false;
		}
	}
	_directory = dir;
	_directory.makePath();
	return true;
}
Ejemplo n.º 2
0
void KFile::replaceAll(KData& str)
{
	int pos;
	KData dtKData = "\\";
	while ((pos = str.find(dtKData)) != -1)
	{
		str.replace(pos, 1, "/");
	}
}