Rename a file

T

tom

Hello, got a prob with renaming a file; still don't know where is the
mistake.
this is the code:
<%
'***************************************************************************
*
file_orig=session("nome_file")
file_copy=session("id_risp") & "_" & session("id_recl")
'path_copy=Server.Mappath("/document/" & file_copy & ".doc")

'response.write(file_orig)&"<br>"
'response.write(file_copy)&"<br>"
'response.end

Dim fso
set fso = Server.CreateObject("Scripting.FileSystemObject")
fso.MoveFile file_orig, file_copy <--( ROW: 117 )
set fso = nothing
%>


and this is the Error :

Microsoft VBScript runtime error '800a0035'

File not found

/aaaa/bbbb/zzzz/frm_risp_new_sql.asp, line 117



Have u got any clue?
 
A

Aaron [SQL Server MVP]

Well, can you uncomment this and tell us the results? Have you verified
that the file exists?
'response.write(file_orig)&"<br>"

You can also use the FileExists method, e.g.

if not fso.FileExists(file_orig) then
response.write "Couldn't find " & file_orig
else
' ... do stuff with file ...
end if
 
P

Paul Baker [MVP, Windows - SDK]

What are the values of file_orig and file_copy and does file_orig exist?

What is the intended purpose of path_copy and why is it commented out?

Paul
 
B

Bob Barrows [MVP]

tom said:
Hello, got a prob with renaming a file; still don't know where is the
mistake.
this is the code:
<%
'***************************************************************************
*
file_orig=session("nome_file")
file_copy=session("id_risp") & "_" & session("id_recl")
'path_copy=Server.Mappath("/document/" & file_copy & ".doc")

'response.write(file_orig)&"<br>"
'response.write(file_copy)&"<br>"
'response.end

Dim fso
set fso = Server.CreateObject("Scripting.FileSystemObject")
fso.MoveFile file_orig, file_copy <--( ROW: 117 )
set fso = nothing
%>


and this is the Error :

Microsoft VBScript runtime error '800a0035'

File not found

/aaaa/bbbb/zzzz/frm_risp_new_sql.asp, line 117



Have u got any clue?

My guess: make sure you're looking for the right file. I see you have some
response.writes commented out. Have you verified that the correct path and
file are being stored in file_orig? If so, does the user account have
sufficient file system permissions for this file?

Bob Barrows
 
R

Ray Costanzo [MVP]

What is the value of file_copy?

file_copy=session("id_risp") & "_" & session("id_recl")
RESPONSE.WRITE file_copy
RESPONSE.END

Ray at home
 
A

Aaron [SQL Server MVP]

file_orig=session("nome_file")
| Result -> ( original_file_uploaded.ext )

This needs a PATH, not just a bare filename! Maybe try
server.mappath(session("nome_file")) if you want the file to be in the same
folder as the ASP code. Or, consider defining a path. If you give it just
a filename, it looks in C:\windows\system32\ and I can pretty much guarantee
that "all the permission" are not fine there (nor should they be).

A
 
T

tom

Just want to reply back to all of you. hope to be clear on every points.
( same_file_with_2ID_joined_by_the_underscore.doc )

esult ->( c:\inetpub\wwwroot\document\24_32.doc ) (example)

path is commented cause I wanted to check out where the file was going to be
saved.In fact I didn't understand either why I've got the
path of my local computer and not the one of the server.

Then I checked all the permission and they are all fine.

Other thing I want to add is that all the files are going to be saved in
that folder called "document" and to be overwritten to the file if
it is already uploaded, so this is the issue why I would change the name of
file with the 2 IDs.

cheers, let me know if u want more details,
- tommy
 
T

tom

The 'session("nome_file") ' is related to another file called
uploadclass.asp
inside of this class we've got functions that defined more points about the
file is going to be uploaded.
So I've got also a function that defines the path of the file as well.
Maybe was a thought of mine cares about the path, but actually is not my
first problem cause ,
when I upload a file is going straight to the folder 'document'.
The real issue I want to solve is just rename my file.
I used the fso.MoveFile but doesn't work properly.
So I would ask you if eventually, you've got other alternative solutions
without using the Server.Mappath and so on
but simply substitute the name.this thing drives me nut.
thanks
 
A

Aaron [SQL Server MVP]

The real issue I want to solve is just rename my file.

Okay, you STILL have to pass a VALID PATH to the MoveFile (or any other FSO)
method/property. You weren't doing that, you were just giving it a file
name, so it was looking in system32. Why do you think some other ASP file
has any bearing on what you're doing in this file???

http://www.aspfaq.com/2039#rename
http://www.aspfaq.com/2074
 
B

Bob Barrows [MVP]

Maybe was a thought of mine cares about the path, but actually is not
my first problem cause ,
<snip>

Huh???

Could you rewrite that please? In English? I've read it twice and I still
haven't the slightest idea about what you're trying to say.

Bob Barrows
 
T

tom

Sorry about my english, bob.
I just tried to say, that my first problem is concerning about
renaming a file rather than find out more about the path.
Of course Aaron is right when he says that first I should
sort out with the path.
however I don't know how to behave in this case cause
is a brand new stuff for me, if could give me some advice,
would be appriciated.
thanks
 
B

Bob Barrows [MVP]

Uh-oh. You're not a native English speaker? If so, my apologies. I was
assuming you were being lazy, instead of having problems expressing yourself
in a different language.

However, I'm still having difficulties understanding what your problem is.
Hopefully someone else can help.

Bob Barrows
 
J

Jeff Dillon

Simply hard-code all the values first, and get that working.

c:\origfile.txt

c:\destfile.txt

Jeff
 
P

Paul Baker [MVP, Windows - SDK]

Okay, here it is in plain English.

fso.MoveFile test.txt test2.txt is BAD!
fso.MoveFile c:\test.txt c:\test2.txt is GOOD. c:\test.txt MUST EXIST.

You must pass fully-qualified file name to MoveFile and the source file must
exist.

Paul
 
B

Bob Barrows [MVP]

:)
Sure, but others, including Aaron have said that. How does that address the
rest of his concerns (whatever they are)? He seems to have some sort of
objection to using the path that I just don't understand. Do you?

Bob
 
P

Paul Baker [MVP, Windows - SDK]

Bob,

No, I don't understand. I was trying to just reiterate everyone else's good
advice as clearly and concisely as possible.

If he is renaming a file, it has to exist and he has to know what the file
name is. Nothing else makes sense, and the other IIS related details seem
kind of irrelevant.

Paul
 
T

Tom

this is the actual situation:
I've got a form with 3(+1) fields
0.ID(hidden)
1.Date(irrelevant)
2.Title(irrelevant)
3.File to upload -> Now everytime somebody's going to upload the original
file, the file itself keeps the original name.So at this point I would
change
this name with another one which is the union between the first ID and the
ID
of another table separated by a "_" (example -> "32_15.doc" instead of
"pippo.doc").
I 'm doing this cause I'd like to avoid to overwrite a file.

For what concerns the path instead I still have difficulties to understand
how it works.
cause if am extracting the file's path I get the path of my local computer
which is:
C:\prog\......\document\32_15.doc
I dont know if it is right cause am working straight on the server and not
on my local
PC. So I dont really know if it should have a different path or what. for
example
ip_number\fold_1\fold_2\....fold_n\document\32_15.doc??

Let me know, cheers
 
P

Paul Baker [MVP, Windows - SDK]

Tom,

You have to figure out if the source file exists on the server or not. If
not, how are you going to debug it? Is someone restricting your access to
the server?

Paul
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top