This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
bw:vbscript_tool [2019/10/23 15:30] akoehler [Different dates based on day of the week.] |
bw:vbscript_tool [2022/08/02 16:42] (current) akoehler |
||
|---|---|---|---|
| Line 72: | Line 72: | ||
| ==== Date & time in YYYYMMDDTHHMM format. Useful for timestamping output files ==== | ==== Date & time in YYYYMMDDTHHMM format. Useful for timestamping output files ==== | ||
| - | <code vb> | + | <code vb> |
| + | DateCalc = DatePart(" | ||
| Return " | Return " | ||
| </ | </ | ||
| Line 93: | Line 94: | ||
| ==== Day of the week (1=Sun - 7=Sat) ==== | ==== Day of the week (1=Sun - 7=Sat) ==== | ||
| <code vb> | <code vb> | ||
| - | Return | + | Return |
| ==== Number of days in current month ==== | ==== Number of days in current month ==== | ||
| Line 128: | Line 129: | ||
| ==== Test to see if current date is last day of month ==== | ==== Test to see if current date is last day of month ==== | ||
| - | <code vb>Useful for controlling workflow execution based on month end. | + | Useful for controlling workflow execution based on month end. |
| + | <code vb> | ||
| IF " | IF " | ||
| Return " | Return " | ||
| Line 177: | Line 179: | ||
| Next | Next | ||
| Return" | Return" | ||
| + | |||
| + | ====Produce a comma-delimited list of files in a folder==== | ||
| + | <code vb> | ||
| + | ' Create comma-delimited list of files in a folder | ||
| + | Set objFSO = CreateObject(" | ||
| + | ' Change value of objFolder to the appropriate target | ||
| + | Set objFolder = objFSO.GetFolder(" | ||
| + | Set allFiles = objFolder.Files | ||
| + | dim fileList, outFile, oCount, iCount | ||
| + | ' | ||
| + | If objFSO.FolderExists(objFolder) then | ||
| + | Set oFolder = objFSO.GetFolder(objFolder) | ||
| + | iCount = oFolder.files.count | ||
| + | End If | ||
| + | ' | ||
| + | For Each objFile in allFiles | ||
| + | oCount = oCount + 1 | ||
| + | IF oCount <> iCount Then | ||
| + | outFile = objFile | ||
| + | fileList = (fileList + outFile) + " ," | ||
| + | End IF | ||
| + | IF oCount = iCount Then | ||
| + | outFile = objFile | ||
| + | fileList = (fileList + outFile) | ||
| + | End IF | ||
| + | Next | ||
| + | return " | ||
| + | </ | ||
| + | |||
| ==== Find the oldest file in a folder with a specific extension ==== | ==== Find the oldest file in a folder with a specific extension ==== | ||
| - | <code vb>Dim extension | + | <code vb> |
| + | Dim extension | ||
| extension=" | extension=" | ||
| Set objFSo = CreateObject(" | Set objFSo = CreateObject(" | ||
| Line 342: | Line 374: | ||
| ==== Move Files Based on Contents ==== | ==== Move Files Based on Contents ==== | ||
| - | * Unordered List ItemChange | + | * Change |
| <code vb> | <code vb> | ||
| Const ForReading = 1 | Const ForReading = 1 | ||
| Line 486: | Line 518: | ||
| END IF | END IF | ||
| </ | </ | ||
| + | ==== Find and Replace seconds of a text file ==== | ||
| + | < | ||
| + | Const ForReading = 1 | ||
| + | Const ForWriting = 2 | ||
| + | Dim fs | ||
| + | Dim fname | ||
| + | Dim HasCert | ||
| + | Dim vStartNum | ||
| + | Dim vLength | ||
| + | Dim FileIndex | ||
| + | vStartNum = 1 | ||
| + | vSourcePath = " | ||
| + | vTargetPath = " | ||
| + | Set objfso = CreateObject(" | ||
| + | Set objFile = objfso.OpenTextFile(vSourcePath, | ||
| + | strtext = objFile.ReadAll | ||
| + | sSearchString1 = "< | ||
| + | sSearchString2 = "</ | ||
| + | objFile.Close | ||
| + | While InStr(vStartNum, | ||
| + | FileIndex = FileIndex + 1 | ||
| + | vStartNum = InStr(vStartNum, | ||
| + | vLength = InStr(vStartNum, | ||
| + | strNewText = Mid(strtext, | ||
| + | Set fname = objfso.CreateTextFile(vTargetPath & " | ||
| + | fname.WriteLine strNewText | ||
| + | fname.Close | ||
| + | vStartNum = InStr(vStartNum, | ||
| + | Wend | ||
| + | </ | ||
| + | |||
| + | ====VB Script Variables==== | ||
| + | |||
| + | ^ Name ^ Description | ||
| + | |ScriptCode|The actual VBScript code that is written in the tool| | ||
| + | |StepMessage| During a failure the reason for failure will be populated here| | ||
| + | |StepStatus| True or False| | ||