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

curious problem

Status
Not open for further replies.

GIGN

Programmer
Oct 6, 2000
1,082
NZ
I have an error coming from a FIleExists call I think. As below, if my file already exists - then I need to overwrite it - but move will not do it, so I delete the exisiting one first - but the error is a pain.

Here it is

Set FSO = Server.CreateObject("Scripting.FileSystemObject")
' Grab the file from the temp folder
Set FILE = FSO.GetFile(Server.MapPath(TEMPLocation))

' Attempt to save to specified Folder - same as original

If Not FSO.FileExists(Server.MapPath(destination)) Then
FILE.Move Server.MapPath(destination)
Else
' If the file is already there, we need to delete it first. This is where the access denied error comes from

Call FSO.DeleteFile(Server.MapPath(destination),true)
FILE.Move Server.MapPath(destination)
fileExists = true
 
From -- the method is .moveFile

---------------

object.MoveFile source, destination

This method lets us move one or more files from one location ( the source) to another (destination). Wildcards can be used within the source string, providing it is the last component in the path, to enable the moving of multiple files, but cannot be used in the destination string. Note that if the source does contain wildcards, or if the destination ends with a back-slash (path separator), it is automatically assumed that the destination is an existing folder and any matching files are moved to it.

It is recommended that you use the FileExists method when moving a file - if a source file doesn't exist you'll get an error. An error also occurs if the destination is a directory or an existing file.

Code:
<%
dim filesys
set filesys=CreateObject(&quot;Scripting.FileSystemObject&quot;)
If filesys.FileExists(&quot;c:\sourcefolder\anyfile.html&quot;) Then
filesys.MoveFile &quot;c:\sourcefolder\anyfile.html&quot;, &quot;c:\destfolder\&quot;
End If
%>

---------------

and here's the rest of what they have to say on the subject (in case you haven't discovered them yet, they're the best quick ref out there)

:)
Paul Prewett
penny.gif
penny.gif
 
Well, there is File.Move too, what I want to know is what happens during FileExists that makes the FIle object unable to move itself.

Now I am actually going to copy it now using FSO, since I am going to save a back up, but it is weird that sometimes File.Move works, and sometimes not - it must be in use in some way, perhaps if the delete line was outside the scope of the Move it would work.
P.S. the error comes from the move, not the delete line, however I am not using this code anymore.

bj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top