本文简单介绍下VC创建文件夹和文件。
新建对话框应用程序,然后添加全局变量函数
BOOL FolderExist(CString strPath)
{
WIN32_FIND_DATA wfd;
BOOL bValue=FALSE;
HANDLE hFind=::FindFirstFile(strPath,&wfd);
if( (hFind!=INVALID_HANDLE_VALUE) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )//文件找到
{
bValue = TRUE;
}
::FindClose(hFind);
return bValue;
}
BOOL CreateFolder(CString strPath)
{
SECURITY_ATTRIBUTES attrib;
attrib.bInheritHandle = FALSE;
attrib.lpSecurityDescriptor = NULL;
attrib.nLength = sizeof(SECURITY_ATTRIBUTES);
return ::CreateDirectory(strPath, &attrib);
// return ::CreateDirectory(strPath,NULL);
}
在程序界面上添加按钮
此程序首先获取当前系统时间和当前程序路径,然后在该路径下生成一个MyFolder的文件夹,然后在该文件夹内部生成一个文件名为MyFile+当前时间,后缀为.txt,内容为My Folder and File test!的文件。
void CCreateFolderAndFileDlg: