Solved

rename a file using FileSystemObject

Posted on 2002-04-23
24
531 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
ID: 6963448
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
ID: 6963488
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
ID: 6963506
ALso chcek the security. Make sure IUSR_{yourservername} user has proper permissions
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 11

Expert Comment

by:ASPGuru
ID: 6963530
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
ID: 6963664
cool...I can try that....and let you know the result
0
 

Author Comment

by:apig
ID: 6963676
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
ID: 6963709
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
ID: 6963715
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
ID: 6963730
yes I do have enctype="multipart/form-data"...so what should I do?
0
 
LVL 20

Expert Comment

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

Author Comment

by:apig
ID: 6963747
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
ID: 6963751
Close your browser where it has already opened or close it from the software which opens it
0
 

Author Comment

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

Expert Comment

by:jitganguly
ID: 6963801
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
ID: 6963815
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
ID: 6964728
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
ID: 6965028
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
ID: 6965037
why?
0
 
LVL 9

Expert Comment

by:AlfaNoMore
ID: 6965071
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
ID: 6965109
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
ID: 6965140
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
ID: 6966978
>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
ID: 7025693
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
ID: 7025746
i'm not sure, if that solves something, but have you tried givin the IWAM_* user rights?

ASPGuru
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Age between date range query (SP) 13 65
sql to convert to date IF entry is in date format 4 81
Copy only dates 3 89
SP to delete duplicates 15 70
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 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