Reputation: 2019
I am attempting to bulk move my files to new folders that have new names. For example, I want to move all files from:
C:\cat\
C:\dog\
To:
C:\test\cat-1234\
C:\test\dog-2477\
I have about 400 folders that I want to move this way.
The destination folder will always CONTAIN the original folder name.
Upvotes: 0
Views: 366
Reputation: 149305
Yes you can copy files from one folder to the other. You can use the API SHFileOperation
:) It will also give you the animated look which you see when windows copies files from 1 folder to the other :) Here is an example. Please amend it for your actual needs.
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
Upvotes: 1
Reputation: 441
I think there is no such thing as bulk move, even if you write a batch program, the OS will only let you do it one file at the time.
Upvotes: 0