View Full Version : Changing File Name on server
isleshocky77
10-11-2002, 09:08 PM
How would u recommend changing the name of a file using pure ASP?
whammy
10-11-2002, 09:56 PM
Hmm... there might be a better way than this, but you could copy the file (with a new filename), and delete the old one... using Scripting.FileSystemObject
http://www.w3schools.com/asp/met_getfilename.asp
Roy Sinclair
10-11-2002, 10:14 PM
If you're going to use the File System Object then get a File Object for the file in question and simply alter it's Name property.
isleshocky77
10-11-2002, 10:26 PM
How would I do this?
Roy Sinclair
10-11-2002, 10:34 PM
<%
dim fso ' as File System Object
dim fo ' as File Object
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fo = fs.GetFile("fileNameBeforeRename")
fo.Name = "fileNameAfterRename")
Set fo = Nothing
Set fso = Nothing
%>
whammy
10-11-2002, 11:42 PM
Duh... of course, that makes more sense. That's one of the few things I HAVEN'T done to a file using FSO, so I didn't know the syntax offhand... ;)
P.S. You have an extra parentheses in there, though:
dim fso ' as File System Object
dim fo ' as File Object
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fo = fs.GetFile("fileNameBeforeRename")
fo.Name = "fileNameAfterRename"
Set fo = Nothing
Set fso = Nothing
P.S. You still might want to check out the link I posted, to make sure that the NEW filename doesn't overwrite a current file... http://www.w3schools.com has a wealth of knowledge in their examples.
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.