Updating a script for efficiency. A JAL Script calls the VBScript in a loop to check each file in a txt file.
What I need help on is to take the file name, add the FormattedDT (date/time) to it (original file name is FullFileName), then copy it over to an archive folder:
\\a70tsgnaeasa001\eas\server\log\archive
For example if the file name from the txt file it is reading from is:
\\A70TSGNAEASA001\d$\EAS\Server\FIPS\BCBSFIPS.TXT
and it was last modified 10/27/2017 at 3:00, then I would want the destination to be:
\\a70tsgnaeasa001\eas\server\log\archive\BCBSFIPS_10_27_2017_03_00_00.TXT
I am having trouble figuring out how to remove the .extension, appending the date/time of the file, and then copying it to the archive folder. I put the code I have so far below.
TXT File Format:
REM there is a comment here on the first line
\\filepath1
\\filepath2
...
\\filepathN
VBScript:
option explicit
Dim SFSO, f, WSSL, FullFileName, txtFile, exitCode, txtLine, ArchiveFolder,
DateFolder, CopyFileName
Dim ArchDT, FormattedDT, mon, day, yr, hr, min, sec, FileNameArray
ArchiveFolder = "\\\\A70TSGNAEASA001\\eas\\Server\\log\\Archive\\"
Set SFSO = CreateObject("Scripting.FileSystemObject")
Set WSSL = Wscript.CreateObject("WScript.Shell")
exitCode = 0
'tests for no args
If WScript.Arguments.Count = 0 then
WScript.quit (9999)
End If
txtFile = WScript.Arguments(0)
DateFolder = ArchiveFolder&Year(Date)&"-"&Month(Date)&"-"&Day(Date)&"\\"
SFSO.CreateFolder(DateFolder)
Set f = SFSO.OpenTextFile(txtFile)
On Error Resume Next
Do Until f.AtEndOfStream
txtLine = f.ReadLine
If(Left(txtLine,2) = "\\") Then
FullFileName = txtLine
' Check for file exists
If SFSO.fileexists(FullFileName) Then
' create archive folder path
'get modified date time, format to _mm_dd_yyyy_hh_mm_ss
ArchDT = CDate(SFSO.DateLastModified(FullFileName))
mon = Month(ArchDT)
day = Day(ArchDT)
yr = Year(ArchDT)
hr = Hour(ArchDT)
min = Minute(ArchDT)
sec = Second(ArchDT)
FormattedDT = "_"&mon&"_"&day&"_"&yr&"_"&hr&"_"&min&"_"&sec
' File name with date/time appended to it
FileNameArray = Split(FullFileName, "\")
ShortFileName = FileNameArray(UBound(FileNameArray))
FileNameArray2 = Split(ShortFileName, ".")
CopyFileName =
DateFolder&FileNameArray2(0)&FormattedDT&FileNameArray2(1)
'copy file to archive folder
SFSO.CopyFile FullFileName, CopyFileName
Else
'exitCode = 9999
End If
End If
Loop
f.Close
SFSO.Close
WScript.quit(exitCode)