Solved

Copy and rename files using VBScript

Posted on 2004-04-18
7
135,026 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
Industry Leaders: 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!

 
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

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

Suggested Solutions

Title # Comments Views Activity
How to make an ADE file by code? 11 109
vbModal 12 74
Dinamic report to Crosstab query 9 59
Win 10 Automation Error with .doCmd in Access 2 89
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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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