Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Copy and rename files using VBScript

Posted on 2004-04-18
7
Medium Priority
?
135,346 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 54

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 54

Accepted Solution

by:
Ryan Chong earned 500 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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:ADP india
ID: 22471139
Thank you .... It helps me
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

810 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