Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-01-2020, 09:21 AM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 90
Smile [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.

Last edited by Rhudi; 09-01-2020 at 11:52 AM. Reason: [SOLVED]
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 05:25 AM.