Make Sure Path Exists

Introduction

Sure, you can use the API version of MakeSureDirectoryPathExists function to satisfy your needs, but there must be an alternative way. What do you need to do if you want to use the API MakeSureDirectoryPathExists function?

First, you have to include 'imagehlp.h' into your project file and point to the 'imagehlp.lib' file so you can link to it. The result is that you will never know how an API function is implemented. Additionally, the size of your released executable file that uses it will blow up.

I dare to present my two versions of a functions to perform the same task as MakeSureDirectoryPathExists does. The main purpose any of them is to make sure the required path exists. If it doesn't, the function creates the nessesary folders to fit the requested path. These functions are not recursive -- they are fast, small and universal.

How Does It Work?

Both versions works as the API MakeSureDirectoryPathExists function but a little bit occuratly. Note the second parameter of each function. It tells a function whether a filename is included to the path or isn't. It is necessary because you may create a file without an extension and thus there is no way to determine is there a folder name or a filename without an extension. The same, you may create a folder with an extension and here we go again, there is no way to determine is there a filename or a folder name with an extension. Only you can tell a function the way it has to work.
When you provide a path a function does not care if there any trailing slash or back slash presents. The difference between the MFC version and the "C" version is that "C" version is a little bit faster, requires no additional memory usage and cares both the slash and the back slash symbols. You can pass CString object to the "C" version fuction and that's ok.

Cool down - btw nice code

You made a nice code, Boy. Change your tune (R U some Russian?) nobody is against you. Those are visiting this site are not idiots beleive me, are they? So do not put capitals and comments on people who made some comment on your code and not on you. It is not a personal attack.
Good job however with some small missing items.

I respect your codes anyway...

really take us lots of time and something else, for examples, eyesight, to explore the way we need in MSDN or somewhere else, for example, on the Internet.

Thus I sincerely respect your work. I just have written a little piece of codes doing nearly the same thing before I remember to find more here...//faint. It took me some time. and really take me some eyesight,hehe.

Top White Papers and Webcasts

Live Event Date: March 19, 2015 @ 1:00 p.m. ET / 10:00 a.m. PT
The 2015 Enterprise Mobile Application Survey asked 250 mobility professionals what their biggest mobile challenges are, how many employees they are equipping with mobile apps, and their methods for driving value with mobility.
Join Dan Woods, Editor and CTO of CITO Research, and Alan Murray, SVP of Products at Apperian, as they break down the results of this survey and discuss how enterprises are using mobile application management and private …

Companies undertaking an IT project need to find the right balance between cost and functionality. It's important to start by determining whether to build a solution from scratch, buy an out-of-the-box solution, or a combination of both. In reality, most projects will require some system tailoring to meet business requirements. Decision-makers must understand how much software development is enough and craft a detailed implementation plan to ensure the project's success. This white paper examines the different …