Move a folder (with several files in it) from one location to the other

Hi,

How do I move a folder with files from one location to the other? It is basically windows cut and paste. Couldn't find any thing in File Management VBO or not sure if I'm missing some thing. Is there anything readily available to carry out the task?

Thanks..
 

sivagelli

Well-Known Member
There is no built-in action to move folders, you have to extend the File Management VBO to 'Move Directory'.

Try this code-

Add an action on to File Management VBO and name it as 'Move Directory'.

Start stage inputs being 'FromPath' and 'ToPath'
Add a Page stage which referes to 'Directory Exists' page and pass the 'FromPath' as an Input. Get the output in to 'Exists' data item. Add a Decision stage with [Exists] as expression. Connect the Yes path to Code Stage with the below code. The inputs for Code stage are 'FromPath' and 'ToPath'. Output of Code stage are 'Success' (Flag type) and 'Error' (Text type). Connect this to End Stage.
The No path of the Decision stage will be connected to a multi Calc stage to make 'Success' as False and 'Error' to have expression: [FromPath] & " does not exist". Connect this to End Stage.

Code:
Dim FSO As Object
Dim FolderName as String

Try
    'removes \ from the FromPath, if any
    If Right(FromPath, 1) = "\" Then
        FromPath = Left(FromPath, Len(FromPath) - 1)
        FolderName = Right(FromPath, Len(FromPath)- InStrRev(FromPath,"\"))
    End If
    
    'Gets the name of the Folder
    'Checks the position of the \ from reverse order
    'using Right() function extracts the characters after \
    FolderName = Right(FromPath, Len(FromPath)- InStrRev(FromPath,"\"))

    'removes \ from the ToPath, if any
    If Right(ToPath, 1) = "\" Then
        ToPath = Left(ToPath, Len(ToPath) - 1)
    End If

    FSO = CreateObject("scripting.filesystemobject")

    'Moves the folder to the destination folder
    FSO.MoveFolder(Source:=FromPath, Destination:=ToPath &"\" & FolderName)

    Success = True

Catch Ex as Exception
    Success = False
    Error_Message = Ex.ToString()

End Try

End stage will have Success and Error as output parameters.

Publish this action and Save. Now, you are good to use this new object to move the directory from a location to another location.

Post back how it goes.
 
Top