搜索文件和改变文件属性
来源:互联网 发布:岑春煊 知乎 编辑:程序博客网 时间:2024/05/17 22:27
The following example copies all text files in the current directory to a new directory of read-only files named \TEXTRO. Files in the new directory are changed to read only, if necessary.
The application uses the GetCurrentDirectory function to retrieve the current directory path. This function is also used to return to the current directory after changing to the \TEXTRO directory.
The application then creates the \TEXTRO directory by using the CreateDirectory function.
The application searches the current directory for all .TXT files by using theFindFirstFile and FindNextFile functions. Each .TXT file is copied to the \TEXTRO directory. After a file is copied, theGetFileAttributes function determines whether the file is read only. If the file is not read only, the application changes directories to \TEXTRO and converts the copied file to read only by using theSetFileAttributes function.
After all .TXT files in the current directory have been copied, the application closes the search handle by using theFindClose function.
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."); }
- 搜索文件和改变文件属性
- Linux-文件权限2(改变文件属性和权限)
- link文件路径及改变文件属性
- linux 改变用户组、文件拥有者、文件属性
- linux 改变用户组、文件拥有者、文件属性 .
- linux文件属性改变
- 搜寻文件和文件属性s,t
- 文件属性和删除只读文件,刷新
- Linux文件属性和更改文件权限
- c获取文件的大小和文件属性、文件查找
- c获取文件的大小和文件属性、文件查找
- Linux改变文件属性与权限
- linux 改变文件属性与权限
- 如何改变文件属性与权限
- 改变android系统下文件属性
- Java创建文件和文件夹、文件属性的读取、文件属性的设置
- VS文件属性(无,编译,内容,嵌入的资源--改变发布网站时,某些文件目录不见了)
- rhs和rhsa文件属性的文件删除方法
- BJT转UTC世界协调时
- 浅入浅出Flask框架:处理客户端通过POST方法传送的数据
- 美团技术文档
- iOS10 用户权限设置问题
- web.xml配置五个有用的过滤器
- 搜索文件和改变文件属性
- Android应用层View绘制流程与源码分析(棒的不行)
- [Python] Lambda 表达式
- JMeter 中 HTTP Cookie 管理器的使用
- 【Java笔试题】哥德巴赫猜想
- getRemoteAddr()和getRemoteHost() 区别
- 易到用车构架演进及上云探索
- mysql 给表和字段加注释
- 浮躁和压力大的时候看看这篇文章