Solved

Copy and rename files using VBScript

Posted on 2004-04-18
7
134,885 Views
Last Modified: 2012-10-29
Hi Everyone -

I need to preform a daily backup of a file by copying an .mdb from one location (Location = C:\Program Files\PARKINVT) renaming it by including the date and time in the field name (File Name = PARK_INVT.mdb), and copying to a backup storage location (Backup Storage Location =  c:\Program Files\PARKINVT\BACKUPS).  Can some one help me on this?

Thanks In Advance!
Kev
0
Comment
Question by:Kevin_S
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 13

Expert Comment

by:Michael_D
ID: 10853641
What do you mean by saying VBScript?
1) If it's just script (or code) written in VB than you can use this:

Dim Location as String
Dim BackupLocation as String
Dim FileName as String
Dim BacupFileName as String

Location = C:\Program Files\PARKINVT
BackupLocation =  c:\Program Files\PARKINVT\BACKUPS
FileName="PARK_INVT.mdb"
BacupFileName ="PARK_INVT_" & Format$(Now(),"d-m-yy h-mm") & ".mdb"

FileCopy Location & "\" & FileName, BackupLocation & "\" & BacupFileName

2) If you want to copy file from ASP Page using <SCRIPT language="VBScript"> and bacup files on server let me know and i'll show you how to do it

Regards,

Michael
 
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 10853670
Try:

Dim fso
set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile " C:\Program Files\PARKINVT\PARK_INVT.mdb", "c:\Program Files\PARKINVT\BACKUPS\PARK_INVT" & Replace(FormatDateTime(Date(),2),"/","")  & ".mdb"
set fso = nothing
msgbox "Done!"
0
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 125 total points
ID: 10853819
If want to include time, just use:

fso.CopyFile "C:\Program Files\PARKINVT\PARK_INVT.mdb", "c:\Program Files\PARKINVT\BACKUPS\PARK_INVT" & Replace(FormatDateTime(Date(),2),"/","") & Replace(FormatDateTime(Time(),4),":","") & ".txt"

btw, are you executing the vbscript in a .vbs file or in a VB application? FYI, Format function is Not allowed in vbscripts writtin in a .vbs file.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Author Comment

by:Kevin_S
ID: 10855131
QUOTE "btw, are you executing the vbscript in a .vbs file or in a VB application? FYI, Format function is Not allowed in vbscripts writtin in a .vbs file."

I am executing the VBScript in a .vbs file not a VB Application.  Are you saying the FormatDateTime function won't work in a .vbs file?  Just wanted to clarify as I copied what you provided above and it works perfectly..?

Also - would be willing to throw in another 65 points (all I have left!) if you could tell me how - using the fso.CopyFile method I could copy all files from one location (without knowing the exact names of the files) to another.  If not, no biggie I'll award you the 125 as offered with the question.

Thanks Again for the help - really appreciate it!

Kev
0
 
LVL 1

Author Comment

by:Kevin_S
ID: 10855428
never mind Ryan - got it working myself!  Thanks for your help!

Kev
0
 
LVL 13

Expert Comment

by:Michael_D
ID: 10856771
Here the method to copy all files in directory to another folder:
 
        Dim fso As New FileSystemObject
         Dim f As Folder, sf As Folder, path As String, newName as String
         
         path = "C:\Program Files\PARKINVT\"

         
         Set f = fso.GetFolder(path)
         'Iterate through subfolders.
         For Each sf In f.SubFolders
           newName=sf.Path & "\backup\" & sf.Name
           fso.CopyFile sf.Path & "\" & sf.Name,  newName
         Next

        set fso=nothing
0
 

Expert Comment

by:adpindia
ID: 22471139
Thank you .... It helps me
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now