Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Backup VB script


Recommended Posts

Make the script look exactly like this:

 

code:

'////////////////////////////////////////////////////////////////////////////////

'//

'// Author: Mick George [email protected]

'// Date: 28/08/2002 02:29 PM

'// File Name: SAVEBACKUP.VBS

'//

'// Description: Example of backing up current drawing.

'//

'// Comments: Original example by Mick George

'// Modified by bryan (_at_) steeplechasetool (_dot_) com

'// Modified by Mick George 7/11/2003 8:30:24 PM

'//

'////////////////////////////////////////////////////////////////////////////////

 

'///////////////// My Constants /////////////////

Public Const fsoDRIVE_UNKNOWN = 0

Public Const fsoDRIVE_REMOVABLE = 1

Public Const fsoDRIVE_FIXED = 2

Public Const fsoDRIVE_NETWORK = 3

Public Const fsoDRIVE_CDROM = 4

Public Const fsoDRIVE_RAM_DISK = 5

Public Const DEF_CENTERED = " "

Public Const DEF_ERRLOG = "C:McScriptErr.log"

 

Public Const DEF_BACKUP_DIR = "C:mcamxmcxMillback up" ' -- Edit to your taste

 

 

 

' -- Start Script

Call Main()

 

 

' ////////////////////

' Sub Declaration

' ////////////////////

Sub Main()

 

On Error Resume Next

 

Dim strBackupPath

Dim strOriginalPath

Dim FSO

Dim strYear

Dim strMonth

Dim strDay

Dim strHour

Dim strMin

 

Set FSO = CreateObject("Scripting.FileSystemObject")

' -- Make sure theres a disk in the floppy drive

'// If CBool(CheckDrive("A:")) Then

 

' -- Check to make sure backup folder is valid

If FSO.FolderExists(DEF_BACKUP_DIR) Then

' -- Make sure we have a drawing to save

If Not IsDrawing Then

ShowString "No current drawing" & DEF_CENTERED

' -- Bail

Exit Sub

End If

 

 

' -- Store current drawings name

strOriginalPath = GetCurrentFileName

''

'' ' -- Assign a new Mc filename

'' '//strBackupPath = "A:Backup.MC9"

'' strBackupPath = "C:TEMP"

''

 

' -- Format a time and date stamp and strip illegal chars

strYear = Replace(FormatDateTime(Date, vbShortDate), "/", "")

strHour = Replace(FormatDateTime(Time, vbShortTime), ":", "")

 

 

'' strYear = CStr( DatePart( "yyyy", Date ) )

''

'' strMonth = CStr( DatePart( "m", Date ) )

''

'' If Len(strMonth) < 2 Then strMonth = "0" & strMonth

''

'' strDay = CStr( DatePart( "d", Date ) )

''

'' If Len(strDay) < 2 Then strDay = "0" & strDay

''

'' strHour = CStr( DatePart( "h", Now ) )

''

'' If Len(strHour) < 2 Then strHour = "0" & strHour

''

'' strMin = CStr( DatePart( "n", Now ) )

''

'' If Len(strMin) < 2 Then strMin = "0" & strMin

''

' -- Build fullpath

''strBackupPath = AddBackSlash(DEF_BACKUP_DIR) & FSO.GetBaseName(strOriginalPath) & "." & strYear & strMonth & strDay & "_" & strHour & strMin & "." & FSO.GetExtensionName(strOriginalPath)

strBackupPath = AddBackSlash(DEF_BACKUP_DIR) & FSO.GetBaseName(strOriginalPath) & "." & strYear & "_" & strHour & "." & FSO.GetExtensionName(strOriginalPath)

 

Call ClearMenuAndPrompts

 

' -- Display current file in prompt area

Call WriteString("Backing up file, please wait...")

 

 

If SaveMCAs(strBackupPath, False) Then

'//ShowString "File backup to floppy drive successful" & DEF_CENTERED

ShowString "Backup to " & DEF_BACKUP_DIR & " complete" & DEF_CENTERED

Else

ShowString "Could not backup file to " & DEF_BACKUP_DIR & DEF_CENTERED

End If

 

' -- Switch back to original file

'Call SaveMCAs(strOriginalPath, False)

Call SaveMCAs(strOriginalPath, True)

 

Call ClearMenuAndPrompts

 

Call RepaintScreen (True)

 

Else

''ShowString "Please insert a disk into drive A:" & DEF_CENTERED

ShowString "Folder " & DEF_BACKUP_DIR & " does not exist!" & DEF_CENTERED

Exit Sub

End If

 

 

If Err Then Call TrapError("Sub::Main", Err, True)

 

Set FSO = Nothing

 

End Sub

 

' ////////////////////

' Sub Declaration

' ////////////////////

Sub TrapError(sSource, objErr, bLogIt)

 

Dim sMSG

Dim sLogError

Dim FSO

 

 

sMSG = "Following error occurred in this script:" & DEF_CENTERED & vbCrLf & vbCrLf

sMSG = sMSG & objErr.Description & DEF_CENTERED & vbCrLf

sMSG = sMSG & "Number: " & objErr.Number & DEF_CENTERED & vbCrLf

sMSG = sMSG & "Source: " & DEF_CENTERED & sSource

 

ShowString sMSG

 

 

If bLogIt Then

 

sLogError = "Error " & objErr.Number & " in " & sSource & ":" & vbCrLf & objErr.Description

Call WriteLog(sLogError)

 

End If

 

objErr.Clear

 

Set objErr = Nothing

 

End Sub

 

 

' ////////////////////

' Sub Declaration

' ////////////////////

Sub WriteLog(sLogMessage)

 

On Error Resume Next

 

Dim FSO

Dim fsoStream

 

Set FSO = CreateObject("Scripting.FileSystemObject")

 

Set fsoStream = FSO.CreateTextFile(DEF_ERRLOG, True)

 

fsoStream.WriteLine String(78, "-")

fsoStream.WriteLine "---" & FormatDateTime(Now, vbGeneralDate) & "---"

fsoStream.WriteLine sLogMessage

fsoStream.WriteLine GetScriptEngineInfo

 

fsoStream.Close

 

' -- Clean up

Set fsoStream = Nothing

Set FSO = Nothing

 

If Err Then Call TrapError("Sub::WriteLog", Err, False)

 

End Sub

 

' ////////////////////

' Function Declaration

' ////////////////////

Function GetScriptEngineInfo()

 

On Error Resume Next

 

Dim s

s = "" ' Build string with necessary info.

s = ScriptEngine & " Version "

s = s & ScriptEngineMajorVersion & "."

s = s & ScriptEngineMinorVersion & "."

s = s & ScriptEngineBuildVersion

 

GetScriptEngineInfo = s ' Return the results.

 

If Err Then Call TrapError("GetScriptEngineInfo", Err, True)

 

 

End Function

 

' ////////////////////

' Function Declaration

' ////////////////////

Function CheckDrive(sPath)

 

On Error Resume Next

 

Dim FSO

Dim fsoDrive

 

Set FSO = CreateObject("Scripting.FileSystemObject")

 

' -- Get the "A" drive

Set fsoDrive = FSO.GetDrive(sPath)

 

Select Case fsoDrive.DriveType

' -- Only interested in a Floppy drive...

Case fsoDRIVE_REMOVABLE: CheckDrive = fsoDrive.IsReady

Case Else

' -- Force failure

CheckDrive = False

End Select

 

 

' -- Clean up

Set FSO = Nothing

Set fsoDrive = Nothing

 

If Err Then Call TrapError("Function::CheckDrive", Err, True)

 

 

End Function

 

 

' ////////////////////

' Function Declaration

' ////////////////////

 

Function AddBackSlash(sPath)

 

If Right(sPath, 1) <> "" Then sPath = sPath & ""

AddBackSlash = sPath

 

End Function

 

 

' ////////////////////

' Function Declaration

' ////////////////////

 

Function IsDrawing()

 

Dim Ret

 

Ret = StartDBSearch(mc_alive, -1)

 

IsDrawing = Ret

 

End Function

I'm also assuming that you have the rights to create files in C:mcamxmcxMillback up and in the root of C (C:).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...