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

Moving Files

Status
Not open for further replies.

OzzieBloke

Programmer
Mar 28, 2004
31
AU
Is there a way to move a file from one folder to another??

I tried using shell("move " & FilenameandPath) but the filename has to be very basic. The files that I want to move contain -'s and a few other symbols.
 
Try using the scripting filesystemobject. Maybe something like this:
Code:
Set oFSO = CreateObject("Scripting.FileSystemObject")
oFSO.MoveFile("C:\temp\Somes File with 's.txt", "C:\Program Files\")
 
Is there some sort of patch required for this??

Every thing I try doesn't work.

The file that I am trying to move depends on what is in a list box. Basically there is a lot of files that need to be moved. What I have tried so far is
Code:
    Dim FSO, FileSet
    For N = 0 To MoveList.ListCount - 1
        Set FSO = CreateObject("Scripting.FileSystemObject")
        Set FileSet = App.Path & "\" & MoveList.List(N)
        FSO.movefile(FileSet[COLOR=red], [/color red]"F:\Audio")
    Next
It keeps coming up with an error on the comma in red.
 
You appear to be attempting to pass a collection to the move command. It will not accept a collection as an argument. You need to process through the collection passing each file individually to the move command.
 
As far as I know it is individually moving the files, it starts at the top of the list, and performs the command for each line in the list.

I removed the brackets around the source and destination of the file, this remove the error about the comma, however it still comes up with an error saying that the file already exists.
 
FSO.movefile(FileSet, "F:\Audio")

The code above, I believe, renamed your file to "Audio" and moved it to the F drive.

I think this will help

FSO.movefile(FileSet, "F:\Audio\")

Hope this is it,
CA
 
Did you mean
Code:
Dim FSO, DESTFILE
For N = 0 To MoveList.ListCount - 1
    Set FSO = CreateObject("Scripting.FileSystemObject")
    DESTFILE = (App.Path & "\" & MoveList.List(N))
    FSO.MoveFile "F:\Audio", DESTFILE
Next
That doesn't work
 
RE to CA

The file name remains the same throughout. It is moved to a folder called Audio in F:
 
Try this...It works and it's a bit more efficient because the fso object is not being created every time through the loop. If you don't include the "\" at the end of the destination it will assume you want to move AND rename the file to "Audio", but you want to move the file into the Audio folder and keep the same file name....so this is the code to do that.


Dim fso As FileSystemObject, FileSet As String
Set fso = CreateObject("Scripting.FileSystemObject")
For N = 0 To MoveList.ListCount - 1
FileSet = App.Path & "\" & MoveList.List(N)
fso.MoveFile FileSet, "F:\Audio\"
Next


Thanks,
CA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top