Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I move files

Status
Not open for further replies.

bpeirson

Technical User
Sep 28, 2005
85
CA
I am trying to move 3000 plus files from various subfolders into a common root folder. I found this code but it does not do exactly what I need.

Code:
Sub movefiles()
Dim fto As String
Dim ffrom As String

'folder from
ffrom = "\\original server folder"
'folder to
fto = "\\Destination server folder\"
'looks for any file in the folder from directory
MyFile = Dir(ffrom & "\*", vbNormal)

'moves every file until its empty.
Do While MyFile <> ""
Name ffrom & "\" & MyFile As fto & MyFile
MyFile = Dir
Loop
End Sub

How do I modify this to take all the files in the sub folders of folder "main" and move them all into folder "Main". Another way to look at this is I want to eliminate the subfolders but keepp the files they contain.

 
mitjulep,
[tt]DOS[/tt], that's funny. Be sure to toggle the bus speed on your 286 from 9 to 13 before starting, it'll run faster.

bpeirson,
I'm guessing that you will need to do this multiple times, on multiple machines (user's?) which is why you didn't 'drag-n-drop' the folder.

You can use [tt]Dir()[/tt] and recursion to step through all the sub-directories, but it's slow and IMHO a pain.

I would recomend taking a look at [tt]Application.FileSearch[/tt]. It's really fast, searches sub-directories, will return all or certain files, will return the file and folder information...

You then loop through the [tt]FoundFiles[/tt] collection to move the files.

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
You could use the filesystemobject to move the files once you get the folder names.

Code:
Dim fso As FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile "C:\*.txt", "C:\Temp"
MsgBox "Text Files Moved!", vbInformation

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top