rel="File-List" href="file:///C:%5CDOCUME%7E1%5CMOSESY%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C02%5Cclip_filelist.xml">
判断目录是否存在并创建目录:
- // Test Whether the dir exist
- CString m_dir;
- if (m_dir.Right(1) == “//”)
- m_dir = m_dir.Left(m_dir.GetLength()-1);
- if (GetFileAttributes(m_dir) == FILE_ATTRIBUTE_DIRECTORY)
- return TURE;
- else
- CreateAllDirectory(m_dir);
- // Function CreateAllDirectory
- // recursive function
- void CreateAllDirectory(CString Dir)
- {
- if (Dir.Right(1) == “//”)
- Dir = Dir.Left(Dir.GetLength()-1);
- if (GetFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
- return;
- else if (GetFileAttributes(Dir) != -1)
- {
- if (DeleteFile(Dir)) // delete the file with the same name
- if (CreateDirectory(Dir, NULL))
- return;
- MessageBox(_T(“Can not create directory for captured pictures”), NULL, MB_OK);
- }
- int n = Dir.ReverseFind(‘//’);
- CreateAllDirectory(Dir.Left(n));
- if (!CreateDirectory(Dir, NULL))
- MessageBox(_T(“Can not create directory for captured pictures”), NULL, MB_OK);
- }
判断Dir中某个文件是否存在,还可以通过FileFind来实现:
- BOOL FileExist(CString strFileName)
- {
- CFileFind fFind;
- return fFind.FindFile(strFileName);
- }