×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Backup using a vbscript

Backup using a vbscript

Backup using a vbscript

(OP)
Hello Forum,

I work as a system engineer on the pharma-company astrazeneca. I am currently working on a solution for a backup script since the script in the software that moves the files has stopped working and the vendor does not have a solution. I have worked very little in Vbscript and i do not have the skills to make this script so i am asking for the forums help.

Once everyday at 16:00 (4 pm) the script needs to copy 9 files from the local computer to a network disk. The files are named:
DG(date(year,month,day ex. 191103)(.MB file,.PX file and data base file)
EG(date(year,month,day ex. 191103)(.MB file,.PX file and data base file)
SG(date(year,month,day ex. 191103)(.MB file,.PX file and data base file)

An example of the nine files names from the third of november 2019: DG191103.DB, DG191103.MB, DG191103.PX, EG191103.DB, EG191103.MB, EG191103.PX,SG191103.DB, SG191103.MB, SG191103.PX

The files to be copied everyday has to be yesterdays files, since the files that are named today's date are not completed until new files are created. So the names of the files to be moved should be like DG(date-1).MB and so on.

I am grateful for any help.

Best regards
Hugo Kilander

RE: Backup using a vbscript

(OP)
*Bump*

RE: Backup using a vbscript

Hi Hugo,

I normally don't simply provide code as this is not the purpose of this forum. Also, such a script stopping to work might have various reasons that may not have to do with code at all, e.g. file server change (new name?), new security policies that prohibit VBScript execution, ...

That said, this should get you going:

CODE

Dim fromPath, destPath
Dim fso, foldr, allFiles, fil
dim rex
dim yesterday, datetext

fromPath="C:\myDailyFiles" 'Change to correct folder path with db, mb, and px files
destPath="X:\myBackupFolder\" 'Change to correct backup folder path, make sure to finish with backslash

set rex = CreateObject("VBScript.RegExp")
yesterday=DateAdd("d",-1,Now())
datetext=right(year(yesterday), 2) & month(yesterday) & day(yesterday)

rex.Pattern="(D|E|S)G" & datetext & "\.(DB|MB|PX)"

set fso= CreateObject("Scripting.FileSystemObject")
set foldr=fso.GetFolder(fromPath)
set allFiles=foldr.Files

for each fil in allFiles
	if rex.Test(fil.Name) then
		fso.CopyFile fil.Path, destPath & fil.Name
	end if
next 

"rex" is a so-called "Regular Expression". With it you can match strings against certain patterns. Since the "yesterday" part is different everyday, it must be calculated before implementing it in the pattern.
I did a quick test locally and it did work just fine.

Hope this helps.
MakeItSo

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

RE: Backup using a vbscript

(OP)
Hello and Thank you so much!!!!

I just placed the script on the computer and it work perfectly. You just saved one guy in my team to walk to the bottom floor in a building 500 meters away and copying 9 files everyday. I am so greatfull for your help! thanks2

Best regards
Hugo

RE: Backup using a vbscript

Glad to know it worked right away. Removing unnecessary physical action is what a script is for. bigcheeks

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close