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 Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move A File From One Directory To Another 2

Status
Not open for further replies.

FontanaS

Programmer
May 1, 2001
357
US
I have the following code that searches a directory and lets me know what files are in it.

With Application.FileSearch
.NewSearch
.LookIn = "C:\Documents and Settings\fontanas\Desktop\Pr Plans\"
.SearchSubFolders = True
.Filename = "*"
.TextOrProperty = "*"
.MatchAllWordForms = True
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)

Next i
Else
MsgBox "There were no files found."
End If
End With

It works fine. I am going to open each file and import them into access. I know how to do that part.

I would like to move the file to another directory after i imported the data and closed it. The new directory is located at -

"C:\Documents and Settings\fontanas\Desktop\Pr Plans\Imported"

Any Ideas About The Syntax?
 
I would recommend looking at the MoveFile method of the FileSystemObject.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 

FontanaS,

This may be close to what you want. It takes a dir_path parameter and creates a Folder object for that path. A folder object has a collection of files. The below code then moves each file to the new path.



im fso As FileSystemObject
Dim fso_folder As Folder
Dim txt As String
Dim fso_file As File
Dim i As Long
Dim file_names() As String

' Make a new File System object.
Set fso = New FileSystemObject

' Get the FSO Folder (directory) object.
Set fso_folder = fso.GetFolder(dir_path)

' Make the list of names.
For Each fso_file In fso_folder.Files
fso_file.Move (YourNewPath & fso_file.Name)
Next fso_file


Mordja
 
There's a much easier way even than using FSO. See the VBA Name statement. People often forget that it can change the folder as well as the file name.

Name string-expression1 As string-expression2

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top