;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       Touch() 
;; 
;;ACTION         Sets the last modified timestamp on a file, creating the file if necessary 
;; 
;;AUTHOR         R. Howarth 
;; 
;;VERSION        1.0 - 2008/06/11 
;; 
;;SYNTAX         Touch(FilePath [,TimeStamp]) 
;; 
;;PARAMETERS     FilePath - REQUIRED - String 
;;               - a regular file to be touched. Specify a complete path 
;; 
;;               TimeStamp - OPTIONAL - String 
;;               - date / time to use. If not specified then the current time is used. 
;; 
;;REMARKS        The touch UDF cannot be used to set folder timestamps. 
;;               If you specify only a date then the time will be set to "00:00" 
;;               If you specify only a time then the date will be set to epoch 
;;               Most date formats appear to work as expected 
;; 
;;RETURNS        True if successful, False if not. Error code is returned. *  
;;               *Modified by G.Barnas/InnoTech Consulting to conform to UDF Standards. 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    W2K3, W2K8, W2K12 
;; 
;;EXAMPLES       $iResult=Touch("C:\temp\foo.txt") 
;;               $iResult=Touch("C:\temp\foo.txt","31 Dec 1999") 
;;               $iResult=Touch("C:\temp\foo.txt","23/02/2068 08:00 PM") 
; 
Function touch($_sFile, Optional $_sTimeStamp)
 
  Dim $_fd, $_oShell, $_oFolder, $_sFolder, $_oFile
 
  If Not Exist($_sFile)
   $_fd = FreeFileHandle()
    If @ERROR
      $Touch = Not @ERROR
      Exit @ERROR
    EndIf
 
    If Open($_fd, $_sFile, 1 + 4)
      $Touch = Not @ERROR
      Exit @ERROR
    EndIf
 
    If Close($_fd)
      $Touch = Not @ERROR
      Exit @ERROR
    EndIf
  EndIf
 
  If InStr($_sFile, '\')
    $_sFolder = Left($_sFile, InStrRev($_sFile, '\'))
  Else
    $_sFolder = @CURDIR
  EndIf
  $_sFile = SubStr('\' + $_sFile, InStrRev('\' + $_sFile, '\') + 1)
 
  If Not $_sTimeStamp
    $_sTimeStamp = @DATE + ' ' + @TIME
  EndIf
 
  $_oShell = CreateObject('Shell.Application')
  If @ERROR OR VarType($_oShell) <> 9
    $Touch = Not @ERROR
    Exit @ERROR
  EndIf
 
  $_oFolder = $_oShell.NameSpace($_sFolder)
  If @ERROR OR VarType($_oFolder) <> 9
    $Touch = Not @ERROR
    Exit @ERROR
  EndIf
 
  $_oFile = $_oFolder.ParseName($_sFile)
  If @ERROR OR VarType($_oFile) <> 9
    $Touch = Not @ERROR
    Exit @ERROR
  EndIf
  $_oFile.ModifyDate = $_sTimeStamp
  $Touch = Not @ERROR
 
  Exit @ERROR
 
EndFunction