Reputation: 11407
I am trying to write the modified date of the oldest file in a directory to a text file. At the moment i can write all the file names (i named them the date they were created but) in oldest to newest order but cant seem to limit this to just output the oldest or indeed get the modified or created date/time. My directory is remote in case it makes a diff and my current attempt is as follows:
dir "\\dirxxxx\xxxxxxx\xxxxx\xxxxx\xxxxx\*.*" /b /a-d /o-d`
Any ideas how i can get the creation or modified date of a file written to a text file in same dir?
Upvotes: 0
Views: 1138
Reputation: 11407
Solution: use vbs instead.
Option Explicit
Dim fso, path, file, recentDate, recentFile, objFileHandle
Set fso = CreateObject("Scripting.FileSystemObject")
Set recentFile = Nothing
For Each file in fso.GetFolder("\\xxxxxx\xxxxxxx").Files
If (recentFile is Nothing) Then
Set recentFile = file
ElseIf (file.DateLastModified < recentFile.DateLastModified) Then
Set recentFile = file
End If
Next
If recentFile is Nothing Then
WScript.Echo "no recent files"
Else
WScript.Echo recentFile.DateLastModified
Set objFileHandle = fso.OpenTextFile("\\Vxxxxxx\xxxxx", 2, "True")
objFileHandle.Write(recentFile.DateLastModified)
objFileHandle.Close
End If
Upvotes: 0
Reputation: 37569
try this:
for /f "delims=" %i in ('dir /b/o-d/a-d') do set "oldesttime=%~ti"
>"log.txt" echo %oldesttime%
Upvotes: 3