Last access date of a directory

Hi all
I am searching through 11000 directories and I would like to find the last modified date of each directory. What would be the solution.

Thanks.
r5ur5Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
while( <*> ){  #or whereever your 11000 directories come from
    print "$_ ".localtime((stat)[9])."\n" if -d
}
r5ur5Author Commented:
I tied it but its not giving me any date or time on the command prompt.  I dont understand the format in which I can give the full directory path in the while statement.
For example the network path is "\\compname\c$\temp" then how will it go in the while statement and further how can we get the access time.

Thanks for your response.

ozoCommented:
while( </compname/c$/temp/*> ){  
    print "$_ ".localtime((stat)[9])."\n" if -d
}
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

ADSaundersCommented:
Hi,
Another minor mod of my file recursion function in VBScript (or VB if you prefer)

Just c&p the following into a .vbs file. Run it from a command shell from where you can view the output directly, or redirect to a file. Run from explorer, each echo is t0 a messagebox.

Regards .. ALan

private const SourcePath = "C:\Downloads" ' put your source directory here
'private sub HandleFile (byval f)
'      f.name = fso.getbasename(f.parentfolder) & "." & fso.getextensionname(f.path)
'end sub

Private Sub handlefolder(ByVal folder)
' This (recursive) sub will first of all handle all sub-folders in it's parameter target
' then all files.
' Only need this next 'for each' if you need to to recurse subdirectories in the parameter target
  For Each f In folder.SubFolders ' may not be necessary if there are no subfoldrs to recurse
'    handlefolder  f               '   ''          ''
            WScript.Echo f.path & " :- " & f.DateLastModified
            ' or f.DateCreated or f.DateLastAccessed
  Next                            '   ''          ''
'  for each f in folder.files ' Handle each of the file objects
'    handlefile f
'  next
End Sub

' Main Routine starts here
Dim fso, fo
Set fso = CreateObject("Scripting.filesystemobject")
' Get handle to input folder
Set fo = fso.GetFolder(SourcePath)
handlefolder fo
Set fso = Nothing
Set fo = Nothing

Naveen SwamyYash Infinite Solutions Private LimitedCommented:
hi,
in php its done this way

<pre>
$getLastModDir = filemtime("/path/to/directory/.");
</pre>

or recursive
function mostRecentModifiedFileTime($dirName,$doRecursive) {
   $d = dir($dirName);
   $lastModified = 0;
   while($entry = $d->read()) {
       if ($entry != "." && $entry != "..") {
           if (!is_dir($dirName."/".$entry)) {
               $currentModified = filemtime($dirName."/".$entry);
           } else if ($doRecursive && is_dir($dirName."/".$entry)) {
               $currentModified = mostRecentModifiedFileTime($dirName."/".$entry,true);
           }
           if ($currentModified > $lastModified){
               $lastModified = $currentModified;
           }
       }
   }
   $d->close();
   return $lastModified;
}


r5ur5Author Commented:
Hey OZO
Your solution looks good to me. I tried it and it works. The only problem now I am facing is this that the while loop recursion is already done. How can I pass the whole path to get the modified date. I have the path in a variablle and I would like to get the return value in variable too. In you solution if I take out the while loop how can I get the value back of a particular directory.
Thanks again for your help.
ozoCommented:
If you have a directory path in $variable, you can append the modification time with
$variable .= "\t".localtime((stat $variable)[9])."\n";

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
r5ur5Author Commented:
Thanks OZO for your help. You are genius in PERL. Thanks a lot.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.