Link to home
Start Free TrialLog in
Avatar of sbtSSI
sbtSSIFlag for Denmark

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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of GPTJ
GPTJ
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sbtSSI

ASKER

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

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
prog = WshShell.ExpandEnvironmentStrings("%ProgramFiles%")
objStartFolder = prog & "\uptime4\GUI\published\" & Year(Date) & "\" & Maaned
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colSubfolders = objFolder.Subfolders
Set colFiles = objFolder.Files
For Each objFile in colFiles
If DateDiff( "d", objFile.DateLastModified, Date ) = 0 Then
	Filnavn0 = objFile.Name
	pos = InStr(Filnavn0,"_")
	Filnavn1 = (Left(Filnavn0,pos-1)) & "_current.html"
	objFSO.CopyFile objStartFolder & "\" & Filnavn0 , prog & "\uptime4\GUI\published\sharepoint\"_
         & Filnavn1 , OverwriteExisting
End If
Next

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial