Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Closed Thread
 
Thread Tools Rate Thread Display Modes
  #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]
  #2  
Old 09-01-2020, 09:48 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,482
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.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #3  
Old 09-01-2020, 09:56 AM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 90
Clarification

I edited my post to actually ask my question. :P
  #4  
Old 09-02-2020, 10:29 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,482
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.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Closed Thread


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 10:49 PM.