Move files on Folder A to Folder B based on Foldername

harky

Active Member
Joined
Apr 8, 2010
Messages
289
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:

harky

Active Member
Joined
Apr 8, 2010
Messages
289
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>


 

harky

Active Member
Joined
Apr 8, 2010
Messages
289
*New folder needs to be created if destination doesn't exist.
 

harky

Active Member
Joined
Apr 8, 2010
Messages
289
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
 

harky

Active Member
Joined
Apr 8, 2010
Messages
289
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:

harky

Active Member
Joined
Apr 8, 2010
Messages
289
*and it also delete empty folder after moved.
 
Last edited:

harky

Active Member
Joined
Apr 8, 2010
Messages
289
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
33,720
Office Version
365
Platform
Windows
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
 

harky

Active Member
Joined
Apr 8, 2010
Messages
289
Hi sorry.

No body advice even i asked in few site :)
http://www.vbaexpress.com/forum/showthread.php?65763-Move-all-files-on-XX-Folder-to-XX-Folder-based-on-excel&p=393772#post393772
https://www.ozgrid.com/forum/forum/help-forums/excel-vba-macros/1222237-marco-excel-move-all-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
 

Forum statistics

Threads
1,085,463
Messages
5,383,844
Members
401,857
Latest member
kevin67

Some videos you may like

This Week's Hot Topics

Top