删除给定类型的文件 IFF 文件夹中没有其他文件类型
我想删除 [cue,jpg,png,m3u,etc.] 类型的某些文件,但当且仅当它们本身位于文件夹中或 [cue,jpg,png,m3u,etc.] 类型的其他文件中时。我已经有一个函数可以获取任何给定文件夹中所有 [cue、jpg、png、m3u 等] 类型的文件并将其作为列表返回,但我只需要根据条件删除所有文件多于。举个例子:文件 q.jpg 单独位于一个文件夹中。 myfunc() 完成后,它将被删除。
编辑 抱歉不清楚。让我举一个更好的例子: 我们有两个文件夹,Alpha 和Beta,位于Gamma 文件夹中。在Alpha中,有三个文件:1.mp3、2.mp3、folder.jpg。在Beta中,有一个文件cover.jpg。 myfunc()
完成后,1.mp3、2.mp3、folder.jpg 应保持不变,而 cover.jpg 应被删除。
I want to delete certain files of type [cue,jpg,png,m3u,etc.] but if and only if they are in a folder by themselves or other files of [cue,jpg,png,m3u,etc.] type. I already have a function that can get me all the files of type [cue,jpg,png,m3u,etc.] in any given folder and return it as a list, but I just need to delete all of it according to the conditions above. To give an example: File q.jpg is in a folder by itself. After myfunc() finishes, it is deleted.
EDIT Sorry for unclearness. Let me give a better example:
We have two folders, Alpha and Beta in folder Gamma. In Alpha, there are three files: 1.mp3, 2.mp3, folder.jpg. In Beta, there is one file cover.jpg. After myfunc()
finishes, 1.mp3, 2.mp3, folder.jpg should be untouched while cover.jpg should be deleted.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您有两个步骤:
1)给定扩展名列表,获取与该扩展名匹配的文件夹中的所有文件的列表。
2)如果目录中的所有文件都有与您的列表匹配的扩展名,请删除它们
请注意,这不包括有关如何遍历目录结构或要测试哪些目录的任何信息...示例代码有一个目录硬编码在.
It sounds like you have two steps:
1) Given a list of extensions, get the list of all files in a folder matching that extension.
2) If all the files in your directory have an extension matching your list, remove them
Note that this doesn't include any information about how to traverse the directory structure, or which directories to test ... the sample code has a single directory hard-coded in.