如何使用.dll扫描文件夹中文件名列表中的文件 [英] How can I scan file with a file name list inside on the folder using .dll
问题描述
大家好的一天,
i想询问我是如何使用文件夹内的列表扫描文件名然后扫描后它会运行正常,然后如果不在列表名称中,它将自动删除列表中不包含的文件名
示例:
我的文件夹里面有这个文件。
sample1.txt
sample2.txt
sample3 .txt
然后如果文件夹中没有包含某些文件名,它会自动删除该文件。
sample1.txt
sample2.txt
sample3.txt
sample_4.txt
然后sample_4.txt不包含在我的文件列表名称中,然后它会自动删除这些文件。
我尝试过的事情:
hi good day all,
i would like to ask if how can i scan file names with a list inside the folder then after scan it will run ok, then if not in the list names it will auto delete the file name that not include in the list
Example:
inside my folder i got this file.
sample1.txt
sample2.txt
sample3.txt
then if some file name is not include in the folder it will auto delete that file for example.
sample1.txt
sample2.txt
sample3.txt
sample_4.txt
then the sample_4.txt is not include in my file list name then it will auto delete this files.
What I have tried:
hi good day all,
i would like to ask if how can i scan file names with a list inside the folder then after scan it will run ok, then if not in the list names it will auto delete the file name that not include in the list
Example:
inside my folder i got this file.
sample1.txt
sample2.txt
sample3.txt
then if some file name is not include in the folder it will auto delete that file for example.
sample1.txt
sample2.txt
sample3.txt
sample_4.txt
then the sample_4.txt is not include in my file list name then it will auto delete this files.
推荐答案
你所寻求的是DirectoryInfo
类,您可以使用 EnumerateFiles()方法。
这将允许您do是遍历指定目录中的所有文件。在您浏览它们时,您可以根据列表检查名称,并根据具体情况执行您想要的操作。
MS Docs:DirectoryInfo.EnumerateFiles Method(System.IO)| Microsoft Docs [ ^ ]
What you seek is theDirectoryInfo
class, in which you can use the EnumerateFiles() method.
What this will allow you to do is to go through all of the files in a specified directory. While you loop through them, you can check the names against your list and do what you want on a case by case basis.
MS Docs: DirectoryInfo.EnumerateFiles Method (System.IO) | Microsoft Docs[^]
这篇关于如何使用.dll扫描文件夹中文件名列表中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!