• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Files.walkFileTree doesn't check all the directories

 
Rakoczi Markus
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

i have the following code:



my problem is when i start the program it visits only 5 directories with it's subdirectories, but in my /home folder there are much more directories.
What's wrong with my implementation?
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is your folder structure inside the /home directory? I would like to see that.
 
surlac surlacovich
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rakoczi Markus wrote:
my problem is when i start the program it visits only 5 directories with it's subdirectories, but in my /home folder there are much more directories.
What's wrong with my implementation?

There must be no files in "home" folder and it's subfolders.
 
Rakoczi Markus
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
surlac surlacovich wrote:
Rakoczi Markus wrote:
my problem is when i start the program it visits only 5 directories with it's subdirectories, but in my /home folder there are much more directories.
What's wrong with my implementation?

There must be no files in "home" folder and it's subfolders.


Sorry, but what do you mean by "no files in home folder and it's subfolders" ?

@Mansukhdeep Thind

Here is a picture with folder content :


In the source code on my computer of course the path is "/home/myUserName" and the screenshot as well.

only the folders below are visited
.thumbnails
.macromedia
Workspace
.netbeans
.mozilla

in .mozilla folder at one point i get the following ERROR:

java.nio.file.NoSuchFileException: /home/myUserName/.mozilla/firefox/mwad0hks.default/lock
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(UnixFileAttributeViews.java:55)
at sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:143)
at sun.nio.fs.LinuxFileSystemProvider.readAttributes(LinuxFileSystemProvider.java:96)
at java.nio.file.Files.readAttributes(Files.java:1675)
at java.nio.file.Files.size(Files.java:2264)
at test_files.Test_Files$1.visitFile(Test_Files.java:36)
at test_files.Test_Files$1.visitFile(Test_Files.java:32)
at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:135)
at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:199)
at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:199)
at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:199)
at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:199)
at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:69)
at java.nio.file.Files.walkFileTree(Files.java:2591)
at java.nio.file.Files.walkFileTree(Files.java:2624)
at test_files.Test_Files.main(Test_Files.java:32)



 
Paul Clapham
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. So an exception is thrown after those five folders are processed, and processing terminates because of that. Which is why the rest of the folders aren't processed.
 
Rakoczi Markus
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for everyone, problem solved!
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Okay. So an exception is thrown after those five folders are processed, and processing terminates because of that. Which is why the rest of the folders aren't processed.


Why is it that he is unable to access the mozilla folder completely? Has it got something to do with the access Paul?

Rakoczi Markus wrote: Thanks for everyone, problem solved!


Why were you getting an exception when trying to access the directories under mozilla folder? How did you solve it? Was it some access related issue?
 
Rakoczi Markus
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are files in the .mozilla folder where you don't have access or maybe they are temporary in the Cache folder . (Actually if I stop Firefox the program doesn't give error on .mozilla folder).
The solution was to handle the java.nio.file.NoSuchFileException
 
surlac surlacovich
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rakoczi Markus wrote:
Sorry, but what do you mean by "no files in home folder and it's subfolders" ?

Your code prints out files and skips folders without any. So if you have structure of folders in "home" directory without any files, it won't print anything, and you will see it as there wasn't any visits.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rakoczi Markus wrote:There are files in the .mozilla folder where you don't have access or maybe they are temporary in the Cache folder . (Actually if I stop Firefox the program doesn't give error on .mozilla folder).
The solution was to handle the java.nio.file.NoSuchFileException


I was expecting something like this.
 
surlac surlacovich
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rakoczi Markus wrote:
/home/myUserName/.mozilla/firefox/mwad0hks.default/lock


It happens because Firefox uses lock files. But why java throws exception that file doesn't exists?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic