sbtSSI
asked on
Why is 28-04-2009 different from 28-04-2009
Hi Scripting experts
I have made a simple script to rename some html files in a folder but I'm having problems with some of the logic.
I want the script to only copy and rename files from "today" but its not working.
If i change the operator in the line "If Fildato = Date Then" from "=" to "<>" all files are copied and renamed correctly.
Why is 28-04-2009 (Fildato) different from 28-04-2009 (Date) ?!? ;-)
I hope that someone are able to help with this little problem.
Best Regards
Søren
I have made a simple script to rename some html files in a folder but I'm having problems with some of the logic.
I want the script to only copy and rename files from "today" but its not working.
If i change the operator in the line "If Fildato = Date Then" from "=" to "<>" all files are copied and renamed correctly.
Why is 28-04-2009 (Fildato) different from 28-04-2009 (Date) ?!? ;-)
I hope that someone are able to help with this little problem.
Best Regards
Søren
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
prog = WshShell.ExpandEnvironmentStrings("%ProgramFiles%")
objStartFolder = prog & "\uptime4\GUI\published\" & Year(Date) & "\" & (MonthName((Month(Date))))
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
Fildato = (Left(objFile.datelastmodified, 10))
If Fildato = Date Then
pos=InStr(objFile.Name,"_")
Filnavn = (Left(objFile.Name,pos-1)) & "_current.html"
objFSO.CopyFile objStartFolder & "\" & objFile.Name , objStartFolder & "\" & Filnavn , OverwriteExisting
End If
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for the suggestion. I have not had the chance to check up on the data type question, but I found another way to solve the problem.
Insted of using Fildato = Date I changed the script to use DateDiff insted. (Thanks alot to ebgreen and ehvbs on visualbasicscript.com)
The working script ended up looking something like this
Open in new window