• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Folder and file attributes

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 28346
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22818
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22818
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Use the below method to get the folder created date.

 
Rob Spoor
Sheriff
Posts: 22818
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob !!!
 
You ridiculous clown, did you think you could get away with it? This is my favorite tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic