如何修改 Blue Prism 中的代码以移动包含所有内容的文件夹



我遇到了一个问题,移动整个文件夹而不是文件非常方便。

我本人对 Blue Prism 的代码编写经验为 0,但仔细阅读了代码,看看是否可以对其进行修改以满足我的需求。

当我运行此代码时,我收到以下错误消息:

第二个路径片段不得是驱动器或 UNC 名称。

有人能看看我所犯的错误并提出建议吗?请记住,这是新手的工作。提前谢谢你。

输入:文件夹路径、目标

Try
Dim sSourceFolder As String = Folder_Path
Dim sDestinationFolder As String
If Directory.Exists(Destination) Then
    sDestinationFolder = Destination
    If Not sDestinationFolder.EndsWith("") Then
        sDestinationFolder &= ""
    End If
    sDestinationFolder = ""
Else
    sDestinationFolder = ""
    sDestinationFolder = Destination
End If
Dim objDirectoryInfo As DirectoryInfo = New DirectoryInfo(sSourceFolder)
Dim aFolders As DirectoryInfo() = objDirectoryInfo.GetDirectories(sSourceFolder)
For Each oFolder As DirectoryInfo In aFolders
    If sDestinationFolder = "" Then
        oFolder.MoveTo(sDestinationFolder)
    Else
        oFolder.MoveTo(sDestinationFolder)
    End If
Next
Success = True
Message = ""
Catch e As Exception
    Success = False
    Message = e.Message
End Try

我的解决方案在目标中创建一个与源文件夹同名的新文件夹,复制其内容,然后删除源文件夹(通常与移动它相同(。输入保持Folder_PathDestination

Success = True
Message = "" 
Try
    If Not Folder_Path.EndsWith("") Then
        Folder_Path &= ""
    End If
    Dim newDirectory As String = System.IO.Path.Combine(Destination, Path.GetFileName(Path.GetDirectoryName(Folder_Path)))
    If Not (Directory.Exists(newDirectory)) Then
        Directory.CreateDirectory(newDirectory)
    End If
    Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(Folder_Path, newDirectory)
    System.IO.Directory.Delete(Folder_Path, True)
Catch e As Exception
    Success = False
    Message = e.Message
End Try

请确保在对象的"代码选项"中包含 System.IO 命名空间。通过双击"初始化页面/操作"上的描述框并选择相应的选项卡,可以找到代码选项。

最新更新