Pages

Wednesday, 19 October 2011

QTP Script: Move a local or network folder

 

' =============================================================
' function: FolderMove
' desc : Moves a folder and all of its files to a new path
' params : strSourceFolder - the folder to copy
' strDestinationFolder - the location to copy to
' returns : void
' =============================================================

Function FolderMove(strSourceFolder, strDestinationFolder)

 

Dim objFS

 

' create a file system object
Set objFS = CreateObject("Scripting.FileSystemObject")

 

' check that the source folder exists
If Not objFS.FolderExists(strSourceFolder) Then

 

    ' fail if the source does not exist
    reporter.ReportEvent micFail, "Move Folder""Source Folder '"& strSourceFolder &"' Does Not Exist"

 

Else

 

    ' check that the destination folder doesn't already exist
    If Not objFS.FolderExists(strDestinationFolder) Then

        ' move the folder
        objFS.MoveFolder strSourceFolder, strDestinationFolder

 

    Else

 

        ' fail if the target folder was already in place
        reporter.ReportEvent micFail, "Move Folder""Unable to Move Folder as the Target '" & strDestinationFolder & "' Already Exists"

    End If

End If

 

' destroy the object
Set objFS = Nothing

End Function 'FolderMove

 

0 comments:

Post a Comment