?
Solved

Copy and rename files using VBScript

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

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 53

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 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