简体   繁体   中英

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. 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. I filtered list of Microsoft Products from NSRL_FILE . But now I do not want to traverse any windows folder or ms product's folders. 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.

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. 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.

You can try to read the company attribute from the files' meta data and check whether it matches "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.

Take a look at the documentation here: 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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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