Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > optimizing function

Reply
Thread Tools

optimizing function

 
 
puneet vyas
Guest
Posts: n/a
 
      02-26-2009
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_NORMA L);
// 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;
}
}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Optimizing a function? carl C++ 10 12-13-2009 07:35 PM
optimizing function puneet vyas C++ 0 02-26-2009 08:57 AM
Optimizing function pointer usage Jack C++ 2 03-08-2006 05:59 AM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
Optimizing a text statistics function Nickolay Kolev Python 13 04-22-2004 03:16 PM



Advertisments