将文件夹移动到另一个目录

Moving folders to another directory

我最近在这里发布了一个关于将文件移动到另一个目录的问题(),现在我想移动文件夹,然后将其存档。

布局与A中的现有文件夹相同,B中的目标和C列确认是否完成。

提供的代码是

Sub move_files()
    Dim i As Long
    With ActiveSheet
        For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
            Err.Clear
            On Error Resume Next
            Name (.Cells(i, 1)) As .Cells(i, 2) & "\" & StrReverse(Split(StrReverse(.Cells(i, 1)), "\")(0))
            If Err = 0 Then .Cells(i, 3) = "YES" Else .Cells(i, 3) = "NO"
            On Error GoTo 0
        Next
    End With
End Sub

考虑到我正在尝试移动整个列,有谁知道上面是否可以调整以移动文件夹,因为它目前仅适用于文件。我在网上搜索过,但通常只有一个文件。

此为仅移动文件夹的修订版。希望它会起作用。

Sub move_folders()
  Dim i As Long
  Dim oFSO As Object
  Dim sep As String

  Set oFSO = CreateObject("Scripting.FileSystemObject")
  With ActiveSheet
    For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
      Err.Clear
      If Left(StrReverse(.Cells(i, 2)), 1) = "\" Then sep = "" Else sep = "\"
      On Error Resume Next
      oFSO.MoveFolder .Cells(i, 1), .Cells(i, 2) & sep & StrReverse(Split(StrReverse(.Cells(i, 1)), "\")(0))
      If Err = 0 Then .Cells(i, 3) = "YES" Else .Cells(i, 3) = "NO"
      On Error GoTo 0
    Next
  End With
End Sub