File.listFiles () and allocation of physical folders from virtual

The method File.listFiles()displays the contents of the folder. However, on Windows, when you call a method on your root drive, it also gives some - in the absence of a better phrase - “virtual” folders (for example, “Documents and Settings”, which are replaced by “Users” in recent versions of windows).

If you call listFiles () on one of these "virtual" folders, it always returns null. And this is where my problem is, since I want to recursively go through all the folders. I need a way to filter out these folders and preferably not check their names ...

There are also several additional folders that the average user does not see (for example, “System Volume Information” or the recycle bin folder for this drive), and I would be glad to find a way to filter this data like well without blacklisting the names.

Unfortunately, these folders behave like real ones. I am looking for something like a method File.isSystemFolder().

I am very grateful for any advice.

+3
source share
2 answers

You can filter out these hidden system folders by checking if File#isHidden()returns true.

"" . , New IO 2, Java 7. , Vista/Win7 ( XP).


. 2K3, Documents and Settings true File#isHidden(), . .

+2

, File.isSystemFolder, , " ", JVM, . Balus, - ( , ).

"" - -, , ? C:\Documents and Settings ( , C:\Users) , ? , , , getCanonicalPath().equals(getAbsolutePath()) ( . .. s).

, - , , "". , , - , File, , . , , .

0

Source: https://habr.com/ru/post/1752633/


All Articles