怎么能获得指定目录下的所有文件名? 这两个我不会用。能写详细点吗?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 WIN32_FIND_DATA FileData; HANDLE hSearch; DWORD dwAttrs; char szDirPath[] = "c:\\TEXTRO\\"; char szNewPath[MAX_PATH]; char szHome[MAX_PATH]; BOOL fFinished = FALSE; // Create a new directory. if (!CreateDirectory(szDirPath, NULL)) { ErrorHandler("Couldn't create new directory."); } // Start searching for .TXT files in the current directory. hSearch = FindFirstFile("*.txt", &FileData); if (hSearch == INVALID_HANDLE_VALUE) { ErrorHandler("No .TXT files found."); } // Copy each .TXT file to the new directory // and change it to read only, if not already. while (!fFinished) { lstrcpy(szNewPath, szDirPath); lstrcat(szNewPath, FileData.cFileName); if (CopyFile(FileData.cFileName, szNewPath, FALSE)) { dwAttrs = GetFileAttributes(FileData.cFileName); if (!(dwAttrs & FILE_ATTRIBUTE_READONLY)) { SetFileAttributes(szNewPath, dwAttrs | FILE_ATTRIBUTE_READONLY); } } else { ErrorHandler("Couldn't copy file."); } if (!FindNextFile(hSearch, &FileData)) { if (GetLastError() == ERROR_NO_MORE_FILES) { MessageBox(hwnd, "No more .TXT files.", "Search completed.", MB_OK); fFinished = TRUE; } else { ErrorHandler("Couldn't find next file."); } }} // Close the search handle. if (!FindClose(hSearch)) { ErrorHandler("Couldn't close search handle."); } 上面是查询文件,并修改文件属性的代码,你可以改一改! MFC EDit编辑框(在线等) 界面禁用菜单 有问题 跪求高手来救命! WSARecv()函数连接突然中断问题 ado的sql中where怎么实现条件查询 VC中如何捕捉组合键(如Shift+A等)事件? 谁知道杭州三汇数字信息技术有限公司? 为什么??为什么??在DLL中设置全局钩子函数,其中变量的数值在函数外改不了!!! 怎么样才能访问到链表上的某个元素? 求有关ic卡命令的资料 昨天通过MCSD70-016的考试了,哈哈 你知道怎样用代码触发oicq的收发对话框吗?
HANDLE hSearch;
DWORD dwAttrs;
char szDirPath[] = "c:\\TEXTRO\\";
char szNewPath[MAX_PATH];
char szHome[MAX_PATH];
BOOL fFinished = FALSE;
// Create a new directory.
if (!CreateDirectory(szDirPath, NULL))
{
ErrorHandler("Couldn't create new directory.");
}
// Start searching for .TXT files in the current directory.
hSearch = FindFirstFile("*.txt", &FileData);
if (hSearch == INVALID_HANDLE_VALUE)
{
ErrorHandler("No .TXT files found.");
}
// Copy each .TXT file to the new directory
// and change it to read only, if not already.
while (!fFinished)
{
lstrcpy(szNewPath, szDirPath);
lstrcat(szNewPath, FileData.cFileName);
if (CopyFile(FileData.cFileName, szNewPath, FALSE))
{
dwAttrs = GetFileAttributes(FileData.cFileName);
if (!(dwAttrs & FILE_ATTRIBUTE_READONLY))
{
SetFileAttributes(szNewPath,
dwAttrs | FILE_ATTRIBUTE_READONLY);
}
}
else
{
ErrorHandler("Couldn't copy file.");
}
if (!FindNextFile(hSearch, &FileData))
{
if (GetLastError() == ERROR_NO_MORE_FILES)
{
MessageBox(hwnd, "No more .TXT files.",
"Search completed.", MB_OK);
fFinished = TRUE;
}
else
{
ErrorHandler("Couldn't find next file.");
}
}
}
// Close the search handle.
if (!FindClose(hSearch))
{
ErrorHandler("Couldn't close search handle.");
}
上面是查询文件,并修改文件属性的代码,你可以改一改!