• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Folder and file attributes

 
Imre Tokai
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,


How do I get folder attributes, original date created, folder size and # of records in folder?
For files, I'd want original date created?

What is the simplest approach? I'm checking http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html now


Regards
 
Paul Clapham
Sheriff
Posts: 21116
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Date created" isn't one of the attributes you can get with Java.

The "size" of a folder is always zero, as you will see by calling the appropriate method from the File class. (The documentation says it's unspecified, but in all the environments I have tried it in, you get zero.) If you want to know the sum of the sizes of all the files in a folder, you can write code to compute that.

I don't understand what you mean by "# of records in a folder". If you want a list of the files in a folder, there's a method in the File class which returns such a list.
 
Rob Spoor
Sheriff
Pie
Posts: 20546
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually an array

To calculate the size of a folder you'll need a recursive call. In summary, the size of a folder is the sum of the sizes of all files in the folder, plus the sum of the sizes of all sub folders. The size of those sub folders is the recursive call.
 
Imre Tokai
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your answers!


Remaining issue: Date Created
I'm able to reach: http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html#lastModified()
but not the date created;
However, when I right-click on folder from Windows Explorer I'm able to read "Created:" date. How to get this date via Java?

For folder size i recommend this method:

For records in folder i recommend: http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html#list()

How to get the Date Created for a folder?


Regards
 
Rob Spoor
Sheriff
Pie
Posts: 20546
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Paul said, you can't get this with pure Java. You can use JNI, or perhaps call an external application (although I can't name one for you), but those are your options.
 
Gopi Chella
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Use the below method to get the folder created date.

 
Rob Spoor
Sheriff
Pie
Posts: 20546
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The last modified date is not the create date. The create date is set only once, when the file is created. The last modified date is updated each time the file is, well, modified. Hence the name.
 
Gopi Chella
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic