打开目录文件的函数(打开目录文件的函数怎么设置)

打开目录文件的函数(打开目录文件的函数怎么设置)svg xmlns http www w3 org 2000 svg style display none svg

大家好,我是讯享网,很高兴认识大家。



 <svg xmlns="http://www.w3.org/2000/svg" style="display: none;"> <path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path> </svg> <ol><li>通过调用<strong>GetCurrentDirectory</strong>函数确定当前目录&#xff0c;<strong>GetFullPathName</strong>函数确保在应用程序需要时包含驱动器号&#xff0c;调用<strong>SetCurrentDirectory</strong>函数更改当前目录&#xff1b;</li><li>调用<strong>FindFirstFile、FindNextFile</strong>和<strong>FindClose</strong>函数列出指定目录中的文件&#xff1b;以下为调用实例&#xff1a;<br /> #include &lt;windows.h&gt;<br /> #include &lt;tchar.h&gt;<br /> #include &lt;stdio.h&gt;<br /> #include &lt;strsafe.h&gt;<br /> #pragma comment(lib, “User32.lib”)</li></ol> 

讯享网

void DisplayErrorBox(LPTSTR lpszFunction);

int _tmain(int argc, TCHAR *argv[])
{
WIN32_FIND_DATA ffd;
LARGE_INTEGER filesize;
TCHAR szDir[MAX_PATH];
size_t length_of_arg;
HANDLE hFind = INVALID_HANDLE_VALUE;
DWORD dwError=0;
if(argc != 2)
{
_tprintf(TEXT(“ Usage: %s ”), argv[0]);
return (-1);
}











StringCchLength(argv[1], MAX_PATH, &length_of_arg);

if (length_of_arg &gt; (MAX_PATH - 3))
{
_tprintf(TEXT(“ Directory path is too long. ”));
return (-1);
}



_tprintf(TEXT(“ Target directory is %s


讯享网

”), argv[1]);

hFind = FindFirstFile(szDir, &ffd);

if (INVALID_HANDLE_VALUE == hFind)
{
DisplayErrorBox(TEXT(“FindFirstFile”));
return dwError;
}



do
{
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
_tprintf(TEXT(“ %s



”), ffd.cFileName);
}
else
{
filesize.LowPart = ffd.nFileSizeLow;
filesize.HighPart = ffd.nFileSizeHigh;
_tprintf(TEXT(“ %s %ld bytes ”), ffd.cFileName, filesize.QuadPart);
}
}
while (FindNextFile(hFind, &ffd) != 0);








dwError = GetLastError();
if (dwError != ERROR_NO_MORE_FILES)
{
DisplayErrorBox(TEXT(“FindFirstFile”));
}



FindClose(hFind);
return dwError;
}
void DisplayErrorBox(LPTSTR lpszFunction)
{
// Retrieve the system error message for the last-error code




讯享网

}
4. 调用MoveFileEx、MoveFileWithProcess或MoveFileTransacted函数将目录以及其中包含的文件和子目录移到另一个位置;
5. 应用程序可以使用 FindFirstChangeNotification 函数指定触发更改通知的一组条件。 条件包括对文件名、目录名称、属性、文件大小、上次写入时间和安全性的更改。 此函数还会返回可以使用 wait 函数等待的句柄。 如果满足了等待条件,则 FindNextChangeNotification 可用于提供通知句柄来等待后续更改。 但是,这些函数并不指示满足等待条件的实际更改。

使用 FindCloseChangeNotification 关闭通知句柄。

若要在通知中检索有关特定更改的信息,请使用 ReadDirectoryChangesW 函数。 这两种函数互斥,只能使用其中一种方法;
6.
目录管理总结:
函数 说明
CreateDirectory
新建目录。

CreateDirectoryEx
使用指定模板目录的属性创建新目录。
CreateDirectoryTransacted
使用指定模板目录的属性,以事务处理操作的形式创建新目录。

FindCloseChangeNotification
停止更改通知句柄监视。
FindFirstChangeNotification
创建更改通知句柄并设置初始更改通知筛选条件。

FindNextChangeNotification
请求操作系统在下次检测到相应更改时发出更改通知处理信号。
GetCurrentDirectory
检索当前进程的当前目录。

ReadDirectoryChangesExW
检索描述指定目录中的更改的信息,如果指定了该信息类型,这些更改可以包含扩展信息。
ReadDirectoryChangesW
检索描述指定目录中的更改的信息。

RemoveDirectory
删除现有的空目录。
RemoveDirectoryTransacted
删除现有的空目录作为事务处理操作。

SetCurrentDirectory
更改当前进程的当前目录。





















小讯
上一篇 2025-04-29 23:33
下一篇 2025-05-08 21:47

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/170280.html