{"id":1274,"date":"2011-01-02T10:06:59","date_gmt":"2011-01-02T10:06:59","guid":{"rendered":"https:\/\/www.buarotti.ch\/?p=1274"},"modified":"2012-01-21T10:08:40","modified_gmt":"2012-01-21T10:08:40","slug":"file-handling-log-vbs","status":"publish","type":"post","link":"https:\/\/www.buarotti.ch\/?p=1274","title":{"rendered":"File Handling &#038; Log VBS"},"content":{"rendered":"<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n'#############################################################################\r\n '# File: all3.vbs Version: 1.1\r\n '# Autor: Buanet Productions\r\n '# Date: 04.12.2007\r\n '# Description:\r\n '#\r\n '# History:\r\n '#############################################################################\r\n\r\n ' ## ERROR HANDLING ##\r\n On Error Resume Next\r\n\r\n '## Constant for Eventlog\/Filesystem Objects ##\r\n Const EVENTLOG_SUCCESS = 0\r\n Const EVENTLOG_ERROR_TYPE = 1\r\n Const EVENTLOG_WARNING_TYPE = 2\r\n Const EVENTLOG_INFORMATION_TYPE = 4\r\n Const OverWriteFiles = TRUE\r\n Const DeleteReadOnly = TRUE\r\n Const ForAppending = 8\r\n\r\n '## Path Constant ##\r\n Const Source = &quot;D:\\_KANADA_PROJ&quot;\r\n Const Destination = &quot;\\\\SRV02\\vb$\\&quot;\r\n Const txtlog = &quot;C:\\all3.log&quot;\r\n Const loopTime = 60000 ' 1000 = 1 sec | 60000 = 1 min | 360000 = 1 hour\r\n\r\n '## Creating Objects ##\r\n Set objShell = Wscript.CreateObject(&quot;Wscript.Shell&quot;)\r\n Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)\r\n 'Set objFile = objFSO.CreateTextFile(txtlog)\r\n Set objlog = objFSO.OpenTextFile(txtlog, ForAppending, True)\r\n\r\n Do\r\n\r\n '## Startup Eventlog ##\r\n objShell.LogEvent EVENTLOG_INFORMATION_TYPE, _\r\n &quot;Starting Script --&gt; &quot; &amp; Time\r\n objlog.writeline &quot;&#x5B;&quot; &amp; date &amp; &quot;-&quot; &amp; time &amp; &quot;] Starting Script...&quot;\r\n\r\n ' ## Check if Destination available ##\r\n If Not objFSO.FolderExists(Destination) Then\r\n objShell.LogEvent EVENTLOG_ERROR_TYPE, _\r\n &quot;Destination &quot; &amp; Destination &amp; &quot; is not available.&quot;\r\n objloge.writeline &quot;&#x5B;&quot; &amp; date &amp; &quot;-&quot; &amp; time &amp; &quot;] ERROR: Destination &quot; &amp; Destination &amp; &quot; is not available.&quot;\r\n\r\n Else\r\n\r\n '## check if folders or file exist and copy or move ##\r\n 'If objFSO.FileExists(Source) Then\r\n If objFSO.FolderExists(Source) Then\r\n 'Set objFolder = objFSO.GetFile(Source)\r\n 'objFSO.CopyFile Source , Destination , OverWriteFiles\r\n objFSO.CopyFolder Source , Destination , OverWriteFiles\r\n ' objFSO.MoveFolder(Source , Destination)\r\n objShell.LogEvent EVENTLOG_SUCCESS, _\r\n &quot;File successfully copied. &quot; &amp; Source &amp; &quot; --&gt; &quot; &amp; Destination\r\n objlog.writeline &quot;&#x5B;&quot; &amp; date &amp; &quot;-&quot; &amp; time &amp; &quot;] File successfully copied. &quot; &amp; Source &amp; &quot; --&gt; &quot; &amp; Destination\r\n Else\r\n 'Wscript.Echo &quot;File does not exist.&quot;\r\n objShell.LogEvent EVENTLOG_ERROR_TYPE, _\r\n &quot;File does not exist...!&quot;\r\n End If\r\n\r\n '## 3 Options to delete source after ##\r\n ' ** OPtion = Delete one file **\r\n 'objFSO.DeleteFile(Source)\r\n 'objShell.LogEvent EVENTLOG_SUCCESS_TYPE, _\r\n ' &quot;Delete file successfully --&gt;&quot; &amp; Source\r\n\r\n ' ** Option = Delete all files in a folder **\r\n 'objFSO.DeleteFile(Source), DeleteReadOnly\r\n 'objShell.LogEvent EVENTLOG_SUCCESS_TYPE, _\r\n '&quot;Delete files &quot; &amp; Source &amp; &quot; successfully !&quot;\r\n\r\n '** Option = Delete a folder **\r\n 'objFSO.DeleteFolder(Source)\r\n 'objShell.LogEvent EVENTLOG_SUCCESS_TYPE, _\r\n '&quot;Delete folder &quot; &amp; Source &amp; &quot; successfully !&quot;\r\n\r\n ' ## ERROR HANDLING WITH EVENTS ##\r\n 'If Err.Number &lt;&gt; 0 Then\r\n 'Err.Raise 6\r\n If Err &lt;&gt; 0 Then\r\n objShell.LogEvent EVENTLOG_ERROR_TYPE, _\r\n &quot;Error: &quot; &amp; Err.Number &amp; &quot; - Zeile: &quot; &amp; Err.Line &amp; &quot;, Zeichen: &quot; &amp; Err.Character &amp; vbCrLf &amp; &quot;Beschreibung: &quot; &amp; Err.Description\r\n objlog.writeline &quot;&#x5B;&quot; &amp; date &amp; &quot;-&quot; &amp; time &amp; &quot;] ERROR - Desc: &quot; &amp; Err.Description &amp; &quot; Source: &quot; &amp; Err.Source\r\n objlog.writeline &quot;&#x5B;&quot; &amp; date &amp; &quot;-&quot; &amp; time &amp; &quot;] Error: &quot; &amp; Err.Number &amp; &quot; - Zeile: &quot; &amp; Err.Line &amp; &quot;, Zeichen: &quot; &amp; Err.Character &amp; vbCrLf &amp; &quot;Beschreibung: &quot; &amp; Err.Description\r\n Err.Clear\r\n\r\n End If\r\n\r\n End If\r\n\r\n '## Script end Eventlog ##\r\n objShell.LogEvent EVENTLOG_INFORMATION_TYPE, _\r\n &quot;Script end now --&gt; &quot; &amp; Time\r\n objlog.writeline &quot;&#x5B;&quot; &amp; date &amp; &quot;-&quot; &amp; time &amp; &quot;] Script end now..!&quot;\r\n objlog.writeline &quot;&#x5B;&quot; &amp; date &amp; &quot;-&quot; &amp; time &amp; &quot;] -------------------------------------------------------------------------------------.&quot;\r\n\r\n wscript.sleep loopTime\r\n loop\r\n '## EOF ##\r\n<\/pre>\n<h3>Related Images:<\/h3>","protected":false},"excerpt":{"rendered":"<p>&#8218;############################################################################# &#8218;# File: all3.vbs Version: 1.1 &#8218;# Autor: Buanet Productions &#8218;# Date: 04.12.2007 &#8218;# Description: &#8218;# &#8218;# History: &#8218;############################################################################# &#8218; ## ERROR HANDLING ## On Error Resume Next &#8218;## Constant for Eventlog\/Filesystem Objects ## Const EVENTLOG_SUCCESS = 0 Const EVENTLOG_ERROR_TYPE = 1 Const EVENTLOG_WARNING_TYPE = 2 Const EVENTLOG_INFORMATION_TYPE = 4 Const OverWriteFiles = TRUE Const [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[11],"tags":[],"class_list":["post-1274","post","type-post","status-publish","format-standard","hentry","category-vbscript"],"_links":{"self":[{"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/posts\/1274","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1274"}],"version-history":[{"count":2,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/posts\/1274\/revisions"}],"predecessor-version":[{"id":1276,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=\/wp\/v2\/posts\/1274\/revisions\/1276"}],"wp:attachment":[{"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.buarotti.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}