Click here to Skip to main content
15,893,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I know there is no standard method of creating directories/folders in C++. But I have another question. Can I make sure ALL platforms support a way to create directories/folders? I.E. Is it possible we face a kind of platform that doesn't support directories/folders AT ALL?
Posted

The mkdir[^] function is part of the ANSI C standard. It will exist on any compiler which supports this standard, including GCC, Microsoft Visual C, Intel C, PGI C, and almost all others.

Microsoft has marked this function as deprecated, as it is not 100% safe, and recomends you use _mkdir[^], which only works the Microsoft Visual C compiler.

This function does live in different headers on different compilers however.
You will need to use the method that Johny linked to include the correct headers on the correct compilers.

C++
//Based on http://stackoverflow.com/questions/3627127/writing-cross-platform-c-code-windows-linux-and-mac-osx
#ifdef TARGET_OS_MAC
	#error I dont know where it is on MAC, probably
	#include <sys/stat.h>
#elif defined(__linux__)
	//Linux
	#include <sys/stat.h>
#elif defined(_MSC_VER)
	//Microsoft Visual C compiler
	#include <direct.h>
	#define mkdir _mkdir //Automatically use the safe function on windows
#else
	#error Unknown compiler, probably cygwin or something, probably in
	#include <sys/stat.h>
#endif


EDIT:
Generally you would not manually create a folder (or even files) on a mobile platform. You would make use of their internal functions for databases and storing data.
There are circumstances when manually making a file or folder is acceptable, and these platforms provide methods for doing so.
 
Share this answer
 
v3
Comments
Joseph Marzbani 30-Oct-11 11:13am    
Thanks Andrew
follow the
Link[^] it will guide you very will
 
Share this answer
 
Comments
Joseph Marzbani 30-Oct-11 11:02am    
I meant ALL platforms (windows mobile, android, windows phone 7, ...). Thank you any way
Andrew Brock 30-Oct-11 11:08am    
Android uses Java. You can use the NDK to get C, but Google advise against that, especially for something as trivial as making a folder.

WM/WP7 use C#, I'm not too familiar with the platforms, there may be a way of using C on them.

iPhone uses Objective C, which is a superset of C. This, and my solution will work fine on it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900