VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Rename existing file by appending date of file (https://forums.vandyke.com/showthread.php?t=14270)

Rhudi 09-01-2020 09:21 AM

[SOLVED] Rename existing file by appending date of file
 
In Excel VBA, I know how to get the timestamp of a file, and append a formatted date to that existing file.

In VBS through SecureCRT, I want to do the same thing.
How do I test if a file exists? (I know how to do that - the snip below works as far as telling me I need to add code.)
If the file exists, How do I rename that existing file by appending that file's formatted date? (Figured it out)

This is my skeleton so far:
Code:

Set fso = CreateObject("Scripting.FileSystemObject")
Select Case fso.FileExists(strOutputPath & strOutputFile)
    Case True
        Select Case crt.Dialog.MessageBox("File exists - Save dated copy?", "SAVE FILE?", vbYESNO + vbQUESTION)
            Case vbYESc
                Set f = fso.GetFile(strOutputPath & strOutputFile)
                strFileDate = f.DateCreated
                strFileDate = Year(strFileDate) & "-" & _
                              Right("0" & Month(strFileDate),2)  & "-" & _
                              Right("0" & Day(strFileDate),2)
                crt.Dialog.MessageBox "Date on existing file: " & vbCrLf & _
                                      strFileDate & vbCrLf & vbCrLf & _
                                      "PATH: " & strOutputPath & vbCrLf & _
                                      "OLD:  " & strOutputFile & vbCrLf & _
                                      "NEW:  " & Left(strOutputFile, InStrRev(strOutputFile, ".")) & strFileDate & Mid(strOutputFile, InStrRev(strOutputFile, "."))
                fso.MoveFile strOutputPath & strOutputFile, strOutputPath & Left(strOutputFile, InStrRev(strOutputFile, ".")) & strFileDate & Mid(strOutputFile, InStrRev(strOutputFile, "."))
            Case vbNOc
                ' NOOP
        End Select
    Case False
        ' NOOP
End Select

The worst part of searching is putting in the correct string that returns useful hits.

I had to search multiple pieces, and it's hard to know what is different between SecureCRT-VBS and MS-VBS.

But, the code as shown works as desired. If anyone has suggestions on how to improve it, please rovide.

bgagnon 09-01-2020 09:48 AM

Hi Rhudi,

Are you seeking assistance with something?

If so, it's not clear what exactly your question is and how it involves one of our products. Please clarify.

Rhudi 09-01-2020 09:56 AM

Clarification
 
I edited my post to actually ask my question. :P

bgagnon 09-02-2020 10:29 AM

Hi Rhudi,
Quote:

I had to search multiple pieces, and it's hard to know what is different between SecureCRT-VBS and MS-VBS.
Questions specific to SecureCRT will involve SecureCRT's scripting API -- in other words anything beginning with crt. These are all documented in SecureCRT's Help topic Scripting / Script Objects Reference.


All times are GMT -6. The time now is 06:55 AM.