如何修改 Blue Prism 中的代码以移动包含所有内容的文件夹
How to modify code in Blue Prism to Move folders with all they have inside
我遇到了一个问题,移动整个文件夹而不是文件会非常方便。
我自己有 0 次使用 Blue Prism 编写代码的经验,但我仔细检查了代码以查看是否可以修改它以满足我的需要。
当我 运行 此代码时,我收到此错误消息:
Second path fragment must not be a drive or UNC name.
谁能看看我犯的错误并提出建议?请记住,这是新手的工作。提前谢谢你。
Inputs: Folder Path, Destination
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_Path
和 Destination
:
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
命名空间。可以通过双击初始化 Page/Action 上的描述框并选择适当的选项卡来找到代码选项。
我遇到了一个问题,移动整个文件夹而不是文件会非常方便。
我自己有 0 次使用 Blue Prism 编写代码的经验,但我仔细检查了代码以查看是否可以修改它以满足我的需要。
当我 运行 此代码时,我收到此错误消息:
Second path fragment must not be a drive or UNC name.
谁能看看我犯的错误并提出建议?请记住,这是新手的工作。提前谢谢你。
Inputs: Folder Path, Destination
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_Path
和 Destination
:
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
命名空间。可以通过双击初始化 Page/Action 上的描述框并选择适当的选项卡来找到代码选项。