DIR Function Question

M

Mike

I'm trying to rename files and then move them to a new
folder. The code to rename works. The code to move
works. They don't work together. Attached is the complete
code. Files in the original folder will rename using the
filecopy. Kill works and the original file is gone but the
move never takes place. If I comment out the copy and
kill pharses then the move works fine. What am I doing
wrong?

Thanks
Mike

Sub TEST()
Dim oFSO As Object
Dim inFILE, outFILE, fNAME, fromFOLDER, toFOLDER

Set oFSO = CreateObject("Scripting.FileSystemObject")

inFILE = Dir("C:\DVW\REPORTS\")
fNAME = oFSO.getbasename(inFILE)
oFSO.copyfile inFILE, fNAME & " NGPS" & ".xls"
Kill inFILE

Do While inFILE <> ""
inFILE = Dir
fNAME = oFSO.getbasename(inFILE)
On Error GoTo OOPS
oFSO.copyfile inFILE, fNAME & " NGPS" & ".xls"
Kill inFILE
Loop

fromFOLDER = "C:\DVW\REPORTS\*.XLS"
toFOLDER = "C:\DVW\REPORTS\D9\"

oFSO.movefile fromFOLDER, toFOLDER

Set oFSO = Nothing
OOPS:
If Err <> 0 Then
Err.Clear
End If
End Sub
 
R

RB Smissaert

Maybe simpler to use FileCopy:

Sub test()

FileCopy "C:\File1.txt", "C:\File2.txt"
Kill "C:\File1.txt"

End Sub


RBS
 
B

Bob Phillips

Why not just

Name "C:\File1.txt", "C:\File2.txt"


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
R

RB Smissaert

Bob,

You are right, I keep forgetting that one.
Still it was better than using the Scripting.FileSystemObject.

RBS
 
B

Bob Phillips

I agree. It was only seeing you questioning FSO that made me think of Name.

Regards

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top