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!

FSO.MoveFile fails after already moving the file?

Status
Not open for further replies.

devRyan

Programmer
Sep 1, 2006
104
US
Hi all,

I'm using the FSO in some of my DTS scripts. Everything seems to work fine, except that at the completion of the packages, I always get an error message in the final step, where I archive my source file(even though the steps to actually archive the source file complete successfully).

More info:
I've got several DTS packages that accept either .txt or .xls files as their source. These files are stored in a shared directory, and are placed there programatically via email and some other neat stuff. The files sit in the directory until the DTS packages are run. The data in the files is pumped into a SS2000 db, then the files are timestamped and moved to an archive directory, so as to make room for the next round of source files.

Everything works wonderfully, even the part where the files are moved to the archive, but I still get an error on the call to fso.MoveFile saying that the file can't be found, even though the files are getting renamed and moved successfully.

Here's a piece of my code:
Code:
strFileName = "E:\SourceFiles\Doc.txt"
'MsgBox strFileName
	
dateString = thisDay & thisMonth & thisYear & thisHour & thisMin & thisSec
newFileName = left(strFileName, Instr(strFileName,".")-1)& "_" & dateString & ".txt"
newFileName = replace(newFileName,"SourceFiles","Archive")
'MsgBox newFileName
	
objFSO.MoveFile strFileName, newFileName
objFSO.DeleteFile strFileName
		
set objFSO = NOTHING

Can anyone explain this to me? I've confirmed that the datestamping section has nothing to do with the error, by trying the script without that section.

As a reminder, the script works fine. File names are changed, files are moved, files are deleted, but I still get an error that the file doesn't exist upon package completion.

Thanks for any help,

Ryan
 
I found my problem.

I misunderstood how the MoveFile worked and didn't need to use the DeleteFile. I was sure I had tried it before and MoveFile wasn't actually removing the moved file from the source directory, it was acting more like CopyFile. Hance why I used DeleteFile in the first place.

Anyway, I removed the DeleteFile(which was what was really throwing the error), and all is better.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top