Exemplo n.º 1
0
//============================================================================
//		NFileUtilities::GetDirectorySize : Get a directory size.
//----------------------------------------------------------------------------
uint64_t NFileUtilities::GetDirectorySize(const NFile &theDirectory)
{	NFileIterator				fileIterator;
	NFileList					theFiles;
	NFile						theFile;
	uint64_t					theSize;
	NFileListConstIterator		theIter;



	// Validate our parameters
	NN_ASSERT(theDirectory.IsDirectory());



	// Get the state we need
	theFiles = fileIterator.GetFiles(theDirectory);
	theSize  = 0;



	// Get the size
	for (theIter = theFiles.begin(); theIter != theFiles.end(); theIter++)
		{
		theFile = *theIter;

		if (theFile.IsFile())
			theSize += theFile.GetSize();
		}

	return(theSize);
}
Exemplo n.º 2
0
//============================================================================
//		NFileUtilities::UnmountVolume : Unmount a volume.
//----------------------------------------------------------------------------
NStatus NFileUtilities::UnmountVolume(const NFile &theFile)
{


	// Validate our parameters
	NN_ASSERT(theFile.IsDirectory());



	// Unmount the volume
	return(NTargetFile::UnmountVolume(theFile.GetPath()));
}
Exemplo n.º 3
0
//============================================================================
//		NFileUtilities::GetUniqueFile : Get a uniquely-named file.
//----------------------------------------------------------------------------
NFile NFileUtilities::GetUniqueFile(const NFile &theDirectory, const NString &fileName)
{	NString		nameChild, nameFile, nameExt;
	NRange		extBreak;
	NFile		theFile;
	NIndex		n;



	// Validate our parameters
	NN_ASSERT(theDirectory.IsDirectory());



	// Get the state we need
	if (fileName.IsEmpty())
		{
		nameFile = "Temp";
		nameExt  = ".tmp";
		}
	else
		{
		extBreak = fileName.Find(".", kNStringBackwards);
		if (extBreak.GetSize() == 1)
			{
			nameFile = fileName.GetLeft(  extBreak.GetLocation());
			nameExt  = fileName.GetString(extBreak.GetLocation());
			}
		else
			{
			nameFile = fileName;
			nameExt  = "";
			}
		}



	// Generate a unique name
	n = 0;
	
	while (n < 10000)
		{
		// Build the name
		if (n == 0)
			nameChild = nameFile;
		else
			nameChild.Format("%@ %ld", nameFile, n);

		if (!nameExt.IsEmpty())
			nameChild += nameExt;



		// Check for the file
		theFile = theDirectory.GetChild(nameChild);
		if (!theFile.Exists())
			return(theFile);

		n++;
		}



	// Handle failure
	NN_LOG("Unable to create a unique name");
	theFile.Clear();
	
	return(theFile);
}