众所周知,WinCE下没有当前目录的概念,所有路径都以根目录"\\"为参考。获取进程所在目录的参考代码如下。
1
GetModuleFileName(NULL,gszPath,MAX_PATH);
2 int len = wcslen(gszPath);
3 TCHAR * p = gszPath + len;
4 while ( *-- p != _T( ' \\ ' ));
5 *++ p = _T( ' \0 ' );
2 int len = wcslen(gszPath);
3 TCHAR * p = gszPath + len;
4 while ( *-- p != _T( ' \\ ' ));
5 *++ p = _T( ' \0 ' );
或者
1
GetModuleFileName(NULL,gszPath,MAX_PATH);
2 TCHAR * p = wcsrchr(gszPath, ' \\ ' );
3 *++ p = _T( ' \0 ' );
2 TCHAR * p = wcsrchr(gszPath, ' \\ ' );
3 *++ p = _T( ' \0 ' );
设置目录为隐藏及获取目录属性的参考代码如下。
1
if
(
!
SetFileAttributes(gszPath,FILE_ATTRIBUTE_HIDDEN))
2 {
3 DWORD dwError = GetLastError();
4 CString s;
5 s.Format(_T( " Error ID:%d " ),dwError);
6 AfxMessageBox(s);
7 }
8
9
10 DWORD dwRet = GetFileAttributes(gszPath);
11 CString s;
12
13 s.Format(_T( " 0x%08X " ),dwRet);
14 SetDlgItemText(IDC_STATIC_ATTR,s);
2 {
3 DWORD dwError = GetLastError();
4 CString s;
5 s.Format(_T( " Error ID:%d " ),dwError);
6 AfxMessageBox(s);
7 }
8
9
10 DWORD dwRet = GetFileAttributes(gszPath);
11 CString s;
12
13 s.Format(_T( " 0x%08X " ),dwRet);
14 SetDlgItemText(IDC_STATIC_ATTR,s);
判断文件或目录是否存在的参考代码如下。
1
if
(
-
1
!=
GetFileAttributes(gszPath))
2 {
3 AfxMessageBox(_T( " Exist. " ));
4 }
5 else
6 {
7 AfxMessageBox(_T( " Not Exist. " ));
8 }
2 {
3 AfxMessageBox(_T( " Exist. " ));
4 }
5 else
6 {
7 AfxMessageBox(_T( " Not Exist. " ));
8 }