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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change modified date of msg file

Status
Not open for further replies.

strychtur

Programmer
Jan 18, 2008
1
CA
I have a VB script that changes the name of a msg file to Sender – Subject. Now I am looking to change the modified date to be the received date of the email. I thought the following code should do it, but it does not. The name changes but date does not. Any help would be great.
Cheers
Strychtur

' VBScript source code
On Error Resume Next

Dim olkApp, olkMessage, objFSO, objFile, varFile, varNewFileName, Dir

Set olkApp = GetObject(,"Outlook.Application")

If TypeName(olkApp) <> "Application" Then
Set olkApp = CreateObject("Outlook.Application")
End If

Set objFSO = CreateObject("Scripting.FileSystemObject")

For Each varFile In WScript.Arguments
Set olkMessage = olkApp.CreateItemFromTemplate(varFile)
varNewFileName = ReplaceIllegalCharacters(olkMessage.SenderName & "-" & olkMessage.Subject) & ".msg"
Set objFile = objFSO.GetFile(varFile)
objFile.Name = varNewFileName
Call ModFileDT (objFile.Drive, objFile.Name, olkMessage.ReceivedTime)
Next
Set objFile = Nothing
Set objFSO = Nothing
Set olkMessage = Nothing
Set olkApp = Nothing
WScript.Quit

Function ReplaceIllegalCharacters(strSubject)
Dim strBuffer
strBuffer = Replace(strSubject, ":", "")
strBuffer = Replace(strBuffer, "\", "")
strBuffer = Replace(strBuffer, "/", "")
strBuffer = Replace(strBuffer, "?", "")
strBuffer = Replace(strBuffer, Chr(34), "'")
strBuffer = Replace(strBuffer, "|", "")
ReplaceIllegalCharacters = strBuffer
End Function

Function ModFileDT(strDir, strFileName, DateTime)
Dim objShell, objFolder
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strDir)
objFolder.Items.Item(strFileName).ModifyDate = DateTime
End function
 
I don't believe you can set a modify date to be anything but the actual time of modification and that should be handled by the system.

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.
 
Code:
' changing modified date of file

'------ ModFileDT "c:\a_temp", "test.txt", Now - 10
ModFileDT "c:\a_temp", "test.txt", "1/01/2007 4:18:02 PM"

Function ModFileDT(strDir, strFileName, DateTime)
     
    Dim objShell, objFolder
    
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.NameSpace(strDir)
    objFolder.Items.Item(strFileName).ModifyDate = DateTime
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top