optimizing function

P

puneet vyas

hello, this is the function i wrote for making a series of directory
and subdirectory,is there any optimized way of doing the operation
which i am doing,like using string functions so tht without iterating
over input string path
BOOL DirectoryDetail::CreateSubDirectory(string &dirpath)
{
// File Handle
HANDLE fFile;
// File Information Structure
WIN32_FIND_DATA fileinfo;
// BOOL used to test if Create Directory was successful
BOOL test;
// Counter
int x1 = 0;
// Temporary string Object
string tem = "";
//check Does the file path already exists exist
fFile = FindFirstFile(dirpath.c_str(),&fileinfo);
// if the file exists and it is a directory
if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
// Directory Exists close file and return
FindClose(fFile);
return TRUE;
}
//create directory heirarchy
else
{
int length=dirpath.length();
// Parse the supplied string Directory String
for(x1=0;x1<length;x1++)
{
if(dirpath.at(x1) != '\\')
// if the Charachter is not a \
// else add character to temp string
tem += dirpath.at(x1);
else
{
//create directory one level by level
test = CreateDirectory(tem.c_str(),NULL);
if(test)
SetFileAttributes(tem.c_str(),FILE_ATTRIBUTE_NORMAL);
// if the Character is a \ Add the temp string to the vector of string
tem += "\\"; // Now add the \ to the temp string
}
}
// Close the file
FindClose(fFile);
// Now lets see if the directory was successfully created
fFile = FindFirstFile(dirpath.c_str(),&fileinfo);
// if the file exists and it is a directory
if(fileinfo.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
// Directory Exists close file and return
FindClose(fFile);
return TRUE;
}
else
{
FindClose(fFile);
return FALSE;
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top