如何遍历所有包含特殊文件的子文件夹?
我想遍历特定文件夹的所有子文件夹并检查其中是否有特殊文件,否则删除子文件夹。
举个例子(file.txt 是这里的特殊文件):
- folder_all
- 文件夹1
- 文件.txt
- 文件夹2
- 文件.txt
- 文件夹3
- 空
- 文件夹1
因为“folder3”没有该文件,所以我想删除它。
这就是我想做的。有什么想法吗?
非常感谢!
I want to traverse all sub-folders of a particular folder and check whether they have a special file in it otherwise delete the sub-folder.
Take this example (file.txt being the special file here):
- folder_all
- folder1
- file.txt
- folder2
- file.txt
- folder3
- empty
- folder1
Because "folder3" doesn't have the file, I'd like to delete it.
And this is what I want to do. Any ideas?
Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更新的代码
您可以使用RecursiveDirectoryIterator班级:
updated code
You can use the RecursiveDirectoryIterator class:
只需迭代 folderall 的所有子文件夹并检查文件
folder_all/$subfoldername/file.txt
是否存在。如果没有,请将其删除。那应该是一个循环。API:
Simply iterate over all subfolders of folderall and check if the file
folder_all/$subfoldername/file.txt
exists. If not, delete it. That should be one loop.API: