In the age of information explosion, classification of various types of information is already a very necessary function. For example, to save stock market data to a hard disk, you need to separate several directories for storage. For example, when you write logs to the hard disk, You need to divide them into several directories for storage, so that the maintenance staff can find the error information or useful information. For example, when I develop a bank's credit card system, I need to generate all the data transmitted over the network and save the text files to the directory of the day, that is, a directory needs to be created every day, store the logs generated from all transactions. How do you create a directory to meet this requirement? Therefore, you need to use the Windows API function createdirectory to create a directory. Of course, when there are too many directories, you need to call the removedirectory function to delete unnecessary directories. However, the removedirectory function can only delete empty directories, that is, files and subdirectories under the directory can be deleted.
The createdirectory and removedirectory functions are declared as follows:
Winbaseapi
Bool
Winapi
Createdirectorya (
_ In lpcstr lppathname,
_ In_opt lpsecurity_attributes lpsecurityattributes
);
Winbaseapi
Bool
Winapi
Createdirectoryw (
_ In lpcwstr lppathname,
_ In_opt lpsecurity_attributes lpsecurityattributes
);
# Ifdef Unicode
# Define createdirectory createdirectoryw
# Else
# Define createdirectory createdirectorya
# Endif //! Unicode
Winbaseapi
Bool
Winapi
Removedirectorya (
_ In lpcstr lppathname
);
Winbaseapi
Bool
Winapi
Removedirectoryw (
_ In lpcwstr lppathname
);
# Ifdef Unicode
# Define removedirectory removedirectoryw
# Else
# Define removedirectory removedirectorya
# Endif //! Unicode
Lppathname is the directory path.
Lpsecurityattributes is the Security Attribute of the directory.
The returned value is whether the execution is successful.
An example of calling a function is as follows:
#001 // create a directory.
#002 // Cai junsheng 2007/10/16 QQ: 9073204 Shenzhen
#003 STD: wstring strdir (_ T ("C: \ log "));
#004 if (! Createdirectory (strdir. c_str (), null ))
#005 {
#006 outputdebugstring (_ T ("the directory is not created successfully \ r \ n "));
#007
#008}
#009 else
#010 {
#011 // delete an empty directory.
#012 removedirectory (strdir. c_str ());
#013}
#014
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/caimouse/archive/2007/10/16/1828185.aspx