in reply to Analyzing Files Within a Directory
File::Find will do a stat on the file for each file test operator function. stat() returns a big list of information which is cached. Above I used the special variable, underscore, "_" to access different parms of the cached information. This is not needed, but is much faster since only a local cache is being accessed rather than requiring another "expensive" file system operation. However, with only with 8 directories, I doubt this will matter at all in terms of performance.#!/usr/bin/perl use strict; use warnings; use File::Find; $|=1; # turns buffering off on STDOUT so # error messages to unbufferred STDERR wind up # in the right time line order my @directories_to_search = ('.', 'another dir here'); find( \&process_each_file, @directories_to_search ); sub process_each_file { return unless -f $_; # only simple files (no dirs) print "$File::Find::name ctime: ", -C _, "\n"; print "$File::Find::name mtime: ", -M _, "\n"; print "$File::Find::name atime: ", -A _, "\n"; }
Modify @directories_to_search with either relative paths to where this script executes from or absolute paths as per your OS requirements.
I have no idea about what you mean by "start" and "end" times? Can you clarify that?
Update: I looked again this and your terminology of "last create time" set off some warning bells. There isn't any such thing. atime is last time contents where read or written. mtime is the last time that the file contents were modified. ctime is "change time", not create time. This is the most recent of mtime OR the last time file permissions were changed. Whenever anything about a file changes (except its access time), its ctime changes. A Windows, NTFS file system does have the idea of a creation or "born on" time. There are some wild quirks about that and I think we will go far astray talking about that now. I highly doubt that you actually mean "creation time". A special API is needed to get this "creation time" on Windows, -C $filename will not do it.
Under almost all circumstances, the parameter of most interest is the mtime. The time that the contents of the file changed.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Analyzing Files Within a Directory
by huck (Prior) on Mar 15, 2017 at 01:58 UTC | |
Re^2: Analyzing Files Within a Directory
by xc63 (Initiate) on Mar 19, 2017 at 14:52 UTC | |
by Marshall (Canon) on Mar 19, 2017 at 20:08 UTC | |
by afoken (Chancellor) on Mar 21, 2017 at 05:08 UTC | |
by afoken (Chancellor) on Mar 24, 2017 at 07:28 UTC |