Solved

rename a file using FileSystemObject

Posted on 2002-04-23
24
510 Views
Last Modified: 2007-11-27
since there is no rename method in FileSystemObject, I use the following code to rename the file.

Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

objFSO.MoveFile Server.MapPath("/someDir/Foo.asp"), _
                Server.MapPath("/someDir/Bar.asp")

Set objFSO = Nothing

sometimes it works fine, but sometimes I got an error messge  said:


"Server object error 'ASP 0177 : 800a003a'

Server.CreateObject Failed

upload.asp, line 267

The operation completed successfully.
"


0
Comment
Question by:apig
  • 9
  • 6
  • 4
  • +3
24 Comments
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
I think its more of a network problem whiel finding the file.
Use fileexists and then use move
Dim fso, msg
   Set fso = CreateObject("Scripting.FileSystemObject")
   If (fso.FileExists(filespec)) Then
      msg = filespec & " exists."
   Else
      msg = filespec & " doesn't exist."
   End If
   
0
 

Author Comment

by:apig
Comment Utility
thanks, but I did use fileexists before use move...I just found out I did not set another server object to nothing before I use this command...I just fixed that, I'm still testing. hope that helps.

any other suggestion? Thanks
0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
ALso chcek the security. Make sure IUSR_{yourservername} user has proper permissions
0
 
LVL 11

Expert Comment

by:ASPGuru
Comment Utility
you can rename files by just setting the name property to a new value...
maybe this works better....


Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(Server.MapPath("/someDir/Foo.asp"))
f.Name = "Bar.asp"
Set f = Nothing
Set fso = Nothing


ASPGuru
0
 

Author Comment

by:apig
Comment Utility
cool...I can try that....and let you know the result
0
 

Author Comment

by:apig
Comment Utility
I checked the permission for the Iuser, it has full control...but I don't know why when I test once the permission denied error occured.
0
 

Author Comment

by:apig
Comment Utility
I checked the permission for the Iuser, it has full control...but I don't know why when I test once the permission denied error occured.
0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
Do you have
enctype="multipart/form-data ?
like
<form method="POST" action="Upload.asp" enctype="multipart/form-data" name="updform" >
0
 

Author Comment

by:apig
Comment Utility
yes I do have enctype="multipart/form-data"...so what should I do?
0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
Does the uploaded file has permission to IUSR_{yourservername} user ?
0
 

Author Comment

by:apig
Comment Utility
I still can not understand the permission denied error...Is it because of some user is using that file? In my program, the file I want to rename is a jpg file, maybe it is still in cache? If so, how to avoid this?
0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
Close your browser where it has already opened or close it from the software which opens it
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:apig
Comment Utility
I have to do it in ASP code...or how to just clear the cache?
0
 
LVL 20

Expert Comment

by:jitganguly
Comment Utility
Your code should be something like this

Set fso = CreateObject("Scripting.FileSystemObject")
'some stuff...
'....
'....
Set fso = nothing

Now if somebody already opens that jpeg anywhere, you can not control that , meaning you can n ot force him/her to close it.
In your ASP page, you can put the following lines at the top

<%
Response.expires= 0
Response.Expires=-1
Response.Expiresabsolute = Now() - 1
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
%>

But its not 100% full proof not to cache ASP pages
   
0
 

Author Comment

by:apig
Comment Utility
thanks...but I already have to same code in my program...I am still testing, it seems the permission denied error still happens once a while :(
0
 
LVL 20

Expert Comment

by:Silvers5
Comment Utility
Set fso = Server.CreateObject("Scripting.FileSystemObject")
fso.CopyFile ("C:\..users\blabla.doc","C:\..users\blabla44.doc")
fso.DeleteFile "C:\..users\blabla.doc"


check that the file is not opened yet.. it seems the file needs some time to get unlocked before deleting..etc,..  try to use aspwait from www.serverobjects.com
0
 
LVL 9

Expert Comment

by:AlfaNoMore
Comment Utility
Set FSO = Server.CreateObject("Scripting.FileSystemObject")

Should be:

Set FSO = CreateObject("Scripting.FileSystemObject")

i.e. Lose the "Server." command.
0
 
LVL 11

Expert Comment

by:ASPGuru
Comment Utility
why?
0
 
LVL 9

Expert Comment

by:AlfaNoMore
Comment Utility
Because as far as I can tell, it's not a server object. I don't think the Scripting class is a COM object or within MTS, but is a system resource, or something?

Have a look in MSDN, you'll always see the FSO or Dictionary objects being created with CreateObject, and not with a Server.CreateObject.
0
 
LVL 11

Expert Comment

by:ASPGuru
Comment Utility
create each COM object you use in ASP with server.createobject...

the arguments you present aren't relevant.

You always see it just with createobject in MSDN, because they show WSH examples and wsh-scripts don't have a server object.

ASPGuru
0
 
LVL 9

Accepted Solution

by:
AlfaNoMore earned 50 total points
Comment Utility
OK, so my initial observation was wrong. Thought I'd just throw it in there as I never create an FSO object in that manner.

However, I got this from Microsoft:

SYMPTOMS
When you use the FileSystemObject object from an Active Server Pages (ASP) page, you may receive one of the following error messages:

Server object error 'ASP 0177 : 800a0035'
Server.CreateObject Failed
filename.asp, line xx
The operation completed successfully.
-or-
Microsoft VBScript runtime (0x800A0035)
File not found
filename.asp, line xx



CAUSE
This error occurs because FileSystemObject cannot find the file that is being accessed (through the OpenTextFile , DeleteFile , or CopyFile methods, for example). This typically occurs for two reasons:


The file does not exist.


FileSystemObject is not looking for the file in the folder that you had expected. By default, if you do not specify a path, FileSystemObject searches the WinNT\System32 folder.
0
 
LVL 15

Expert Comment

by:robbert
Comment Utility
>sometimes it works fine, but

Simply forget the above.

> upload.asp

From my experience, I can tell that a file that _was_ uploaded (using SoftArtisans' FileUp), and _can_ be seen by Windows Explorer, _may not_ be recognized by the FileSystemObject, instantly, though. There may be an intermediate time (i.e., one second) where the newly created file is visible in Windows Explorer, but pointing the FileSystemObject to it throws an error.

My colleague showed this to me and I found that there was surely no mistake of him, but apparently, a delay with the FileSystemObject.

Unfortunatly, I don't know which solution he took.

Maybe, he had looped until the file appeared (until there was no more error), but this is not perfect solution.

- Hope this helps in recognizing the problem, at least.
0
 

Author Comment

by:apig
Comment Utility
do you know what is the problem?

I always got that error because the file (an image file) I wanted to rename is being used by my another web page. That means that image file is in use, so I got "permission denied" error sometimes. What I can not understand is why this error just happened SOMETIMES?
0
 
LVL 11

Expert Comment

by:ASPGuru
Comment Utility
i'm not sure, if that solves something, but have you tried givin the IWAM_* user rights?

ASPGuru
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now