A
A
Anton Pavlov2020-03-02 13:15:01
VBScript
Anton Pavlov, 2020-03-02 13:15:01

VBScript. File backup. help me figure it out?

Good day. Started learning VBScript. Experienced people advised to set a specific task and look for solutions.
The idea in my head was this:
There is a script that grabs files from one server, puts them on another, and that uses SFTP to distribute to users. Having broken this task into stages, the code is slowly being written, not to say that at an accelerated pace, but still. Looking for examples of using FSO, I came across this example:

Option Explicit

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Dim MySource, MyTarget, MyZipName, MyHex, MyBinary, i
Dim oShell, oApp, oFolder, oCTF, oFile,DT,dateVal
Dim oFileSys
DT = Now
DateVal = Right("0" & Day(DT), 2) & "." & _
          Right("0" & Month(DT), 2) & "." & _
          Year(DT) & "_" & _         
          Right("0" & Hour(DT), 2) & "." & _
          Right("0" & Minute(DT), 2) & "." & _
          Right("0" & Second(DT), 2)
MySource = "E:\files"
MyTarget = "E:\logs\" & dateVal & "_Logs.zip"

MyHex = Array(80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

For i = 0 To UBound(MyHex)
MyBinary = MyBinary & Chr(MyHex(i))
Next

Set oShell = CreateObject("WScript.Shell")
Set oFileSys = CreateObject("Scripting.FileSystemObject")


Set oCTF = oFileSys.CreateTextFile(MyTarget, True)
oCTF.Write MyBinary
oCTF.Close
Set oCTF = Nothing

Set oApp = CreateObject("Shell.Application")

Set oFolder = oApp.NameSpace(MySource)
If Not oFolder Is Nothing Then
oApp.NameSpace(MyTarget).CopyHere oFolder.Items
End If

wScript.Sleep(5000)


Set oFile = Nothing
On Error Resume Next
Do While (oFile Is Nothing)

Set oFile = oFileSys.OpenTextFile(MyTarget, ForAppending, False)
If Err.number <> 0 then
Err.Clear
wScript.Sleep 3000
End If
Loop

Set oFile=Nothing
Set oFileSys=Nothing


The part with the addition of the date / time in the file name, I have already added this.
Due to the lack of knowledge so far, I can not read the logic of the code.
It became interesting how a person realized just the same task. I see an array, and that it refers to external software, but I can’t understand the logic by which the script is executed.
Soryan brothers, if perhaps a primitive question. Google helps to understand snippets of code, but not the flow of the script.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question