Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

optimizing function

0 views
Skip to first unread message
Message has been deleted

puneet vyas

unread,
Feb 26, 2009, 4:21:40 AM2/26/09
to
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;
}
}
}

SG

unread,
Feb 26, 2009, 4:42:10 AM2/26/09
to
On 26 Feb., 09:57, puneet vyas <puneet...@gmail.com> wrote:
> 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,i mean using string functions without iterating over
> string
>
> // recursive directories.cpp : Defines the entry point for the console
> application.
> //
>
> #include "stdafx.h"
> //#include "WriteDir.h"
> #include<stdio.h>
> #include <afx.h>
> #include <CString>
> #include <direct.h>

[snip]

Do you have a concrete question regarding C++ (the language and/or its
standard library)? Most headers you included are Microsoft-specific
and not part of the standard. You might want to ask your question in
another group dedicated to Microsoft extensions/APIs.

Cheers!
SG

0 new messages