I found this solution elsewhere on Mr. Excel to (hopefully) tackle a project I was wanting to take on.
I found this Ron de Bruin automation macro and I want to copy files from a mound of floppy discs to a location on my PC. The problem I am encountering with the code is that if I want to copy from A:\ the macro will copy all files that are inside folders located on A:\ drive but it will not copy anything from the root A:\ directory that is not in a folder.
Further - if I have a floppy with a bunch of files in the root and no folders exist - the macro will error out.
Is there any way to copy from the root?
Sub Copy_Folder()
'This example copy all files and subfolders from FromPath to ToPath.
'Note: If ToPath already exist it will overwrite existing files in this folder
'if ToPath not exist it will be made for you.
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
FromPath = "A:" '<< Change
ToPath = "C:\Admin\My Documents\Floppy Discs" '<< Change
'If you want to create a backup of your folder every time you run this macro
'you can create a unique folder with a Date/Time stamp.
'ToPath = "C:\Users\Ron" & Format(Now, "yyyy-mm-dd h-mm-ss")
If Right(FromPath, 1) = "" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If
If Right(ToPath, 1) = "" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If
FSO.CopyFolder Source:=FromPath, Destination:=ToPath
MsgBox "You can find the files and subfolders from " & FromPath & " in " & ToPath
End Sub
I found this Ron de Bruin automation macro and I want to copy files from a mound of floppy discs to a location on my PC. The problem I am encountering with the code is that if I want to copy from A:\ the macro will copy all files that are inside folders located on A:\ drive but it will not copy anything from the root A:\ directory that is not in a folder.
Further - if I have a floppy with a bunch of files in the root and no folders exist - the macro will error out.
Is there any way to copy from the root?
Sub Copy_Folder()
'This example copy all files and subfolders from FromPath to ToPath.
'Note: If ToPath already exist it will overwrite existing files in this folder
'if ToPath not exist it will be made for you.
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
FromPath = "A:" '<< Change
ToPath = "C:\Admin\My Documents\Floppy Discs" '<< Change
'If you want to create a backup of your folder every time you run this macro
'you can create a unique folder with a Date/Time stamp.
'ToPath = "C:\Users\Ron" & Format(Now, "yyyy-mm-dd h-mm-ss")
If Right(FromPath, 1) = "" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If
If Right(ToPath, 1) = "" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If
FSO.CopyFolder Source:=FromPath, Destination:=ToPath
MsgBox "You can find the files and subfolders from " & FromPath & " in " & ToPath
End Sub
Last edited: