I'm working on a tool to count archived files from another program. Therefor I'm using the DirectoryStream and filter subdirectories and some files with a simple if-clause (shown below).
For the statistics I would like to know, how many documents were created per hour on average.
I'm not very experienced in working with files and directories, but I guess there is some sort of "getLastModified", getting the Timerange from oldest to youngest and the calculate the average number of docs per hour?
Well, files have a
lastModified()
method, returning the timestamp of last modification. It returns 0 if the file does not exist or an I/O error occurred. To convert aPath
to aFile
you can use thetoFile()
method. With that, it will be rather easy to calculate the files/hour average:Edit: Inverted the if condition, to avoid the empty if statement which had code in the else block