我正在尝试将用户指定的文本框中的文件夹复制到用户指定的其他位置,但此代码仅将文件复制到目标而不是文件夹。我正在使用Visual Studio 2005。
这是我的代码:
Dim strDate As String
strDate = DateTime.Now.ToString("yyyy-MM-dd")
Dim sFolderpath
Dim dFolderpath
Dim fs
fs = CreateObject("Scripting.FileSystemObject")
sFolderpath = TextBox1.Text
dFolderpath = TextBox6.Text + "\"
fs.createfolder(dFolderpath & strDate)
fs.copyfolder(sFolderpath, dFolderpath & strDate)
它只将文件复制到目标而不是文件夹本身。 textbox1中的值= C:\ Test \ Test2。 textbox6中的值= K:\ Backup
请帮忙!
答案 0 :(得分:2)
这是VB.Net和VBScript的奇怪组合......
我想〜这就是你所追求的:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim fs As Object = CreateObject("Scripting.FileSystemObject")
Dim sFolderpath As String = TextBox1.Text
Dim sourceFolderName As String = System.IO.Path.GetFileName(sFolderpath)
Dim strDate As String = DateTime.Now.ToString("yyyy-MM-dd")
Dim dFolderpath As String = System.IO.Path.Combine(TextBox6.Text, strDate)
fs.createfolder(dFolderpath)
dFolderpath = System.IO.Path.Combine(dFolderpath, sourceFolderName)
fs.createfolder(dFolderpath)
fs.copyfolder(sFolderpath, dFolderpath)
End Sub
您可能也对this感兴趣。