0

我正在尝试将文件夹从用户指定的文本框中复制到用户指定的另一个位置,但此代码仅将文件复制到目标而不是文件夹。我正在使用 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 中指定的目的地创建一个文件夹,并以今天的日期命名
  • 然后我想从用户在 textbox6 中指定的目的地复制一个文件夹

它仅将文件复制到目标而不是文件夹本身。textbox1 中的值 = C:\Test\Test2。textbox6 中的值 = K:\Backup

请帮忙!

4

1 回答 1

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

您可能也对此感兴趣。

于 2013-07-09T14:51:53.027 回答