Move files on Folder A to Folder B based on Foldername

harky

Active Member
Joined
Apr 8, 2010
Messages
405
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Hi, i really need some help. I had many folder to move :)

I want to move all inside files inside folder a to folder b

*No overwrite of file with same filename as whole
*delete empty folder


From Folder (Col A)Move to Folder (Col B)
\\abc\folder1\\\abc\Main1\
\\abc\folder2\\\abc\Main1\
\\abc\folder3\\\abc\Main2\
\\abc\folder4\\\abc\Main2\
\\abc\folder5\\\abc\Main2\

<tbody>
</tbody>
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi, i really need some help. I had many folder to move :)

I want to move all inside files inside folder a to folder b

*No overwrite of file with same filename as whole
*delete empty folder




From Folder (Col A)Move to Folder (Col B)Status (Col C)
\\abc\folder1\\\abc\Main1\Moved / Cant overwrite
\\abc\folder2\\\abc\Main1\Moved
\\abc\folder3\\\abc\Main2\Moved
\\abc\folder4\\\abc\Main2\Moved
\\abc\folder5\\\abc\Main2\Moved

<tbody>
</tbody>


 
Upvote 0
*New folder needs to be created if destination doesn't exist.
 
Upvote 0
Sorry, i dont know what files is inside the files or the filename so i just want to cut all files in folder A to folder B

By right, there shouldnt have same filename as whole
 
Upvote 0
Samilar to this code but missing status @ Col C
and it also wont delete folder after moved.



Code:
Sub Move_Files_To_NewFolder()
'http://www.rondebruin.nl/folder.htm


'This example move all Excel files from FromPath to ToPath.
'Note: It will create the folder ToPath for you


Dim FSO As Object
Dim FromPath As String, ToPath As String
Dim FileExt As String, FNames As String
Dim LR As Long, i As Long


LR = Cells(Rows.Count, 1).End(xlUp).Row


For i = 2 To LR
    FromPath = Range("A" & i).Value
    ToPath = Range("B" & i).Value
    FileExt = "*.*" '<< Change / You can use *.* for all files or *.doc* for word files
    If Right(FromPath, 1) <> "" Then FromPath = FromPath & ""
    FNames = Dir(FromPath & FileExt)
    If Len(FNames) = 0 Then MsgBox "No files in " & FromPath
    Set FSO = CreateObject("scripting.filesystemobject")
    FSO.CreateFolder (ToPath)
    FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath
Next

End Sub
 
Last edited:
Upvote 0
*and it also delete empty folder after moved.
 
Last edited:
Upvote 0
i try to do it but i think i do it wrong..
there is an error in red

Code:
Sub Move_Files_To_NewFolder()
'http://www.rondebruin.nl/folder.htm


'This example move all Excel files from FromPath to ToPath.
'Note: It will create the folder ToPath for you


Dim FSO As Object
Dim FromPath As String, ToPath As String
Dim FileExt As String, FNames As String
Dim LR As Long, i As Long


LR = Cells(Rows.Count, 1).End(xlUp).Row


For i = 2 To LR
    FromPath = Range("A" & i).Value
    ToPath = Range("B" & i).Value
    FileExt = "*.*" '<< Change / You can use *.* for all files or *.doc* for word files
    
    If Right(FromPath, 1) <> "\" Then FromPath = FromPath & "\"
    FNames = Dir(FromPath & FileExt)
    
   ' If Len(FNames) = 0 Then MsgBox "No files in " & FromPath
    
[COLOR=#0000ff]    If Len(FNames) = 0 Then[/COLOR]
[COLOR=#0000ff]    Cells(i, 3).Value = "No files in Source Path"[/COLOR]
[COLOR=#0000ff]    Else[/COLOR]
[COLOR=#0000ff]    Cells(i, 3).Value = "Folder already exist"[/COLOR]
[COLOR=#0000ff]    End If[/COLOR]


    
    Set FSO = CreateObject("scripting.filesystemobject")
[COLOR=#ff0000]    FSO.CreateFolder (ToPath)[/COLOR]
    FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath
    
Next i


End Sub
 
Upvote 0
Cross posted.
While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.

Please provide all links
 
Upvote 0
Hi sorry.

No body advice even i asked in few site :)
http://www.vbaexpress.com/forum/sho...-XX-Folder-based-on-excel&p=393772#post393772
https://www.ozgrid.com/forum/forum/...-files-in-folder-a-to-folder-b-based-on-excel


Cross posted.
While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.

Please provide all links
 
Upvote 0

Forum statistics

Threads
1,214,857
Messages
6,121,948
Members
449,056
Latest member
FreeCricketId

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