Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LastModifiedDate code

Status
Not open for further replies.

rkapp2

MIS
Aug 7, 2007
12
US
I'm trying to compare a file's LastModifieDate with another. I'm wanting to copy the file once it's LastModifiedDate reaches 32 days. Here is what I have so for. Any help would be much appreciated.

File1 = "C:\Temp\File1.txt"
File2 = "C:\Temp\File2.txt"

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set SrcFile = oFSO.GetFile(File1)
Set CpyFile = oFSO.GetFile(File2)

If SrcFile.DatelastModified <> CpyFile.DatelastModified

Thanks
Richard
 
Is it not working, are you getting an error, ...???

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
It's not working the way I want it to. I want the SrcFile copied if the DateLastModified is 32 days old.
 
I need to target the modified date of the file so I can copy it after X many days. I don't see how I can do this using the DateDiff function.
 
Then you are not looking very hard.

Use the FileSystemObject to bind to the file. Then use
object.DateLastModified to get the date it was last modified. Use dateDiff on that date and compare it to today's date using the Now function. That will give you how many days old the file is since last modification.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Here is the code I have so far. My code does find the file I want copied. I believe my code gets the date the file was modified but the DateDiff you are helping me out with isn't working correctly, most likely my fault. It copies the file no matter what criteria I put in.


Dim oFSO, oFile, NotesID, objNetwork, idFile, idBFile, strUserName

Set oFSO = WScript.CreateObject ("Scripting.FileSystemObject")
Set objNetwork = CreateObject ("WScript.Network")

strUserName = objNetwork.UserName
NotesID = "C:\Lotus\Notes\Data\" & strUserName & ".id "
NotesIDBackup = "\\servername\location\" & strUserName & ".id "

Set oFile = oFSO.GetFile (NotesID)
Set oFile = oFSO.GetFile (NotesIDBackup)

idFile = oFile.DateLastModified
idBFile = oFile.DateLastModified

idFile = DateDiff ("d", dDate, Now)
If idFile >= 5 Then
oFSO.CopyFile NotesIDBackup, "C:\NotesBackup\"
Else
End If
 
Should be more like this

idFile = oFile.DateLastModified
idBFile = oFile.DateLastModified

If DateDiff("d", idFile, Now) >= 5 Then
oFSO.CopyFile NotesIDBackup, "C:\NotesBackup\"
End If

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Looks like it is working the way I want it to. Thanks for helping a neophyte user.
 
I need to compare idFile's and idBFile's modified dates so idFile will be copied after 32 days. I tried....

idFile = oFile.DateLastModified
idBFile = oFile.DateLastModified

If DateDiff ("d", idFile, Now) >=32 DateDiff ("d", idBfile, Now) Then
oFSO.CopyFile NotesID, "C:\NotesBackup\"
End If

I get an error stating and expected "Then" statement is required after >32. Any help would be much appreciated again.
 
>If DateDiff ("d", idFile, Now) >=32 DateDiff ("d", idBfile, Now) Then
[tt]If DateDiff ("d", idbfile, idFile)>=32 Then[/tt]
 
Or maybe the reverse...? I don't know what you want got copied!
[tt]If DateDiff ("d", idFile, idbfile)>=32 Then[/tt]
 
Sure, syntax is no private info. It is always better do your homework in any case. Just because you ask, we sometime answer, sometime not...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top