0

我正在尝试将我的文件批量移动到具有新名称的新文件夹中。例如,我想从以下位置移动所有文件:

C:\猫\
C:\狗\

到:

C:\test\cat-1234\
C:\test\dog-2477\

我想以这种方式移动大约 400 个文件夹。

目标文件夹将始终包含原始文件夹名称。

4

2 回答 2

1

是的,您可以将文件从一个文件夹复制到另一个文件夹。您可以使用 API SHFileOperation:) 它还会为您提供当 Windows 将文件从 1 个文件夹复制到另一个文件夹时所看到的动画外观 :) 这是一个示例。请根据您的实际需要进行修改。

Option Explicit

Private Declare Function SHFileOperation _
Lib "shell32.dll" Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) As Long

Private Type SHFILEOPSTRUCT
    hWnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAborted As Boolean
    hNameMaps As Long
    sProgress As String
End Type

Private Const FO_COPY = &H2

Sub Sample()
    Dim FilePath1 As String, FilePath2 As String

    FilePath1 = "C:\cat"
    FilePath2 = "C:\test\cat-1234"

    '~~> Usage ~~> CopyFolder(From,To)
    '~~> Example ~~> CopyFolder("C:\Temp\1","C:\Temp\2")
    If CopyFolder(FilePath1, FilePath2) Then
        MsgBox "Copied"
    Else
        MsgBox "Not copied"
    End If
End Sub

Private Function CopyFolder(ByVal sFrom As String, _
ByVal sTo As String) As Boolean
    Dim SHFileOp As SHFILEOPSTRUCT
    On Error GoTo Whoa
    CopyFolder = False
    With SHFileOp
        .wFunc = FO_COPY
        .pFrom = sFrom
        .pTo = sTo
    End With
    SHFileOperation SHFileOp
    CopyFolder = True
    Exit Function
Whoa:
    MsgBox "Following error occurd while copying folder " & sFrom & vbCrLf & _
    Err.Description, vbExclamation, "Error message"
End Function
于 2012-05-08T16:41:48.660 回答
0

我认为没有批量移动这样的东西,即使你编写一个批处理程序,操作系统也会让你一次只做一个文件。

于 2012-05-08T16:26:37.447 回答