[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

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

0
sbtSSI
Asked:
sbtSSI
  • 2
2 Solutions
 
GPTJCommented:
This may be a silly question, I know, but humor me.
Have 'Fildato' and 'Date' both been declared as the same data type?
I've seen where there can be a compatibility issue when the data types differ.

Anyway, just a suggestion.
-Tim
0
 
sbtSSIAuthor Commented:
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

0
 
GPTJCommented:
Glad you got it solved.  Very tidy way of doing it, I must say.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now