简体   繁体   English

如何忽略MS Windows文件

[英]How can I ignore MS Windows files

I am working on a project which is used to make a list of files of any specific windows path. 我正在研究一个项目,该项目用于制作任何特定Windows路径的文件列表。 It traverses all files and folder one by one and make a list. 它一个接一个地遍历所有文件和文件夹并列出。 I want to ignore all the MS Windows and MS Product's files. 我想忽略所有MS Windows和MS Product的文件。 I filtered list of Microsoft Products from NSRL_FILE . 我从NSRL_FILE过滤了Microsoft产品列表。 But now I do not want to traverse any windows folder or ms product's folders. 但是现在我不想遍历任何Windows文件夹或ms产品的文件夹。 Does anyone have idea, how can I implement this? 有谁知道,我该如何实施?

NOTE: I do not want to make list of MS Windows and MS Product's related folder name list to ignore while traversing. 注意:我不想在移动时忽略MS Windows列表和MS Product的相关文件夹名称列表。

SOLUTION : I found the solution from this forum link , Its returning following details... 解决方案 :我从此论坛链接中找到了解决方案,它返回了以下详细信息...

CompanyName = Microsoft Corporation
FileDescription = SQM Client
FileVersion = 10.0.14393.0 (rs1_release.160715-1616)
InternalName = sqmapi
LegalCopyright = © Microsoft Corporation. All rights reserved.
OriginalFilename = sqmapi.dll
ProductName = Microsoft® Windows® Operating System
ProductVersion = 10.0.14393.0
OleSelfRegister = 

You're going to have to have a list somewhere of the folder names to ignore. 您将不得不在文件夹名称的某处列出要忽略的列表。 Create a text file with each name to ignore in it. 用每个名称创建一个文本文件,在其中忽略。 Read the file in from your program and if you find a path that matches one in your file, ignore it. 从程序中读取文件,如果在文件中找到与之匹配的路径,请忽略它。 As you find more folders to ignore, you just add them to the list. 当您发现更多要忽略的文件夹时,只需将它们添加到列表中即可。

But now I do not want to traverse any windows folder or ms product's folders. 但是现在我不想遍历任何Windows文件夹或ms产品的文件夹。 Does anyone have idea, how can I implement this? 有谁知道,我该如何实施?

If you do not want to keep a list of names to skip. 如果您不想保留要跳过的名称列表。 The only approach I can think of using Java is to read the meta data from the files. 我能想到的使用Java的唯一方法是从文件中读取元数据。

You can try to read the company attribute from the files' meta data and check whether it matches "Microsoft Corporation". 您可以尝试从文件的元数据中读取公司属性,并检查其是否与“ Microsoft Corporation”匹配。

在此处输入图片说明

The checks can also be based on multiple filter criterias, such as file extension. 检查还可以基于多个过滤条件,例如文件扩展名。

Java has a class known as BasicFileAttributes where you can use it for this purpose. Java有一个称为BasicFileAttributes的类,您可以在其中使用该类。

Take a look at the documentation here: https://docs.oracle.com/javase/7/docs/api/java/nio/file/attribute/BasicFileAttributes.html 在这里查看文档: https : //docs.oracle.com/javase/7/docs/api/java/nio/file/attribute/BasicFileAttributes.html

Note: I am not sure whether this will work perfectly, but this gives you an alternative. 注意:我不确定这是否会完美工作,但这为您提供了替代方法。

Building on user3437460's suggestion, you can examine the owner: 基于user3437460的建议,您可以检查所有者:

String owner = Files.getOwner(path).getName();
boolean isSystemFile = owner.equals("NT SERVICE\\TrustedInstaller");

It's far from perfect, but it's better than nothing. 它远非完美,但总比没有好。

Tested in Windows 7. I have no idea how this behaves in other Windows versions. 在Windows 7中进行了测试。我不知道它在其他Windows版本中的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM