Can Filedate return the create date not the modified date?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
morgandc

Can Filedate return the create date not the modified date?

Post by morgandc » Fri Mar 12, 2004 7:09 pm

It appears that the filedate command is returning the modified date of the file. (Version 6.2.3vb). Is there a way to have it return the create date? I am wanting to delete any files or directories in a folder based on create date. If a person copies an older presentation to the folder it appears to keep the modified date, set's the create date to the date written.

Thanks,
-dm

Lumumba

Post by Lumumba » Sat Mar 13, 2004 3:38 pm

Even my limited mind can recognize the diversity, quality, and usefulness of this compilation. From a reader..."All hand-crafted assembler, tiny and incredibly fast. More than a power-users batch toolkit. There is something here for everybody. How can anyone manage without it?" With excellent, separate documentation for each program. Author: Horst Schaeffer, Germany. (2002). Suggested by Robert Bull.

Homepage

Maybe the date tools (isdate) do what you want to accomplish ...

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Sat Mar 13, 2004 5:13 pm

Hi,

Why not use the FileSystemObject's DateCreated property. Here's a function you can use:


VBSTART

Function GetCreateDate(file)

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(file)
GetCreateDate = f.DateCreated
Set fso = Nothing
Set f = Nothing

End Function

VBEND

VBEval>GetCreateDate("c:\program files\somedir\myfile.txt"),cdate
MessageModal>cdate
MJT Net Support
[email protected]

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Sat Mar 13, 2004 5:24 pm

Taking this further here's a function which will delete files in a specified folder that were created before the specified date:


VBSTART

Function DelCreatedBefore(folderspec,createdate)
Dim fso, f, f1, fc
lastfiledate = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
If f1.DateCreated DelCreatedBefore("c:\program files\mydir",now()),return
MJT Net Support
[email protected]

Morgan

Post by Morgan » Tue Mar 16, 2004 6:05 pm

Wow, that is some support!

I can use VBScript and that get's me started down the right path. I will actually need to set the directory, and delete any files older than x days old in that directory and any subdirectories. If the subdirectory is then empty it needs to be deleted.

Am I getting greedy now or what!

I had looked at the script for finding the last modified file in a dir. When I try and run it, compilation error 1002, line 22, column 6.

I will try the one given for this and check it out.

Thanks,
-dm

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts