Solved

Copy and rename files using VBScript

Posted on 2004-04-18
7
135,089 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 52

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 52

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…

690 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