Copy and Move files and folders

HotLanta

Board Regular
Joined
Nov 3, 2005
Messages
176
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
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
I don’t have my computer in front of me to test this, but this might work.

Try fixing the from path line to this:
Code:
FromPath = “A:\*”
 
Upvote 0
Mr. Odin,

I tried your suggestion and it didn't work for me.
I then changed the path to a local folder in the My Photos directory on my PC and it worked perfectly.

I then changed it to something like A:\Test file.txt and it gave me a error message - something like "file not found".

I wonder if the macro is incapable of seeing the A:\ drive or if this is a Windows 10 issue or something else?

Thanks for your help
 
Upvote 0

Forum statistics

Threads
1,223,276
Messages
6,171,140
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top