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
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