View Full Version : copy and rename file
NancyJ
06-14-2005, 05:03 PM
can anyone tell me how to copy a file from one directory on the server to another directory and give the file a different name?
Or if its even possible.
Basically I have a large number of files I need to move and rename, I could do it by hand but I'd rather not have to.
nikkiH
06-14-2005, 10:00 PM
Sure it's possible...if you give the web server the permission to read and write to those directories / files.
This is not very secure. It's so insecure, EJB (enterprise java beans) forbid such activities and you have to muck around to do it.
AFAIK, .NET doesn't forbid this, but it may have restrictions. (i'm new to .net)
Assuming this is for private use and is secured in other ways and the files and directories are all 777/666 perms, is this classic ASP or .NET? VB or C#?
Once you know that, it's pretty easy to google something like this.
NancyJ
06-15-2005, 10:14 AM
Its classic asp.
Its for a one off bulk transfer and rename. Systems are in place to copy to both these directories automatically in future but we want to move all the past documents too.
Morgoth
06-15-2005, 08:48 PM
This seems like a simple task; However, FSO is always a pain in the butt to use (at least for me).
My suggestion is to open each file in your specific directory, read the text inside of them, and write them to a new file, in a new directory with a name that you can based on the original file name, or what ever name you want.
Does that sound simple enough?
You can get all your refferances from w3Schools:
http://www.w3schools.com/asp/asp_ref_textstream.asp
If you have any problems, don't hesitate to reply.
nikkiH
06-15-2005, 11:47 PM
Its for a one off bulk transfer and rename.
Oh, my. Why mess with all this then?
On *nix, make a simple shell script or perl if you prefer.
In Windows, a simple DOS script (.bat file) or even VB, perl, or Java.
I wouldn't muck about with permissions and all the other jazz of ASP for this. Way more issues than you need for a one-off deal.
I assume this is Windows, since few people use ASP with *nix, so just make a quick perl script to do it. Quick and dirty.
Whatcha got on that box? Java, C, perl...?
(IMO, I agree that VB file system object IS a PITA and I avoid it whenever possible; java slightly less so, but it has issues, too. My choice would be C or perl for this one.)
NancyJ
06-16-2005, 12:20 PM
It was actually very simple to do in asp, there was no messing about necessary and no need to set something up in perl or c.
Dim vTempLocation
vTempLocation = Server.MapPath("/images/news")
dim hTempLocation
hTempLocation = server.mappath("/images/library")
set fs=Server.CreateObject("Scripting.FileSystemObject")
set conn = server.createobject("ADODB.Connection")
set Rs = server.createobject("ADODB.recordset")
conn.Open Application("Data_Conn_ConnectionString")
strSQL = "SELECT * FROM BW_News WHERE BW_Image = 1"
Rs.Open strSQL,conn,adOpenForwardOnly,adLockReadOnly
while not rs.eof
on error resume next
set newsThumb=fs.GetFile(vTemplocation & "\thumb\"& rs("BW_NewsID") & ".jpg")
set newsImage=fs.GetFile(vTempLocation & "\" & rs("BW_NewsID") & ".jpg")
newsThumb.Copy(hTempLocation & "\"&rs("BW_NewsID")&"_th.jpg")
newsImage.Copy(hTempLocation & "\"&rs("BW_NewsID")&"_lo.jpg")
set newsThumb = nothing
set newsImage = nothing
rs.movenext
wend
rs.close
%>
nikkiH
06-16-2005, 03:29 PM
It's about 3 lines of perl code to copy all files of a certain type from one directory to another. ;)
Not sure why you have the DB calls in there. You never mentioned that.
Glad you got it working.
Note for archives: Watch out for permissions problems if you ever need to copy files that aren't writable by the web server. If the web server runs as root, you may have some serious security issues. The web server should run as "nobody".
NancyJ
06-16-2005, 04:06 PM
The call to the db checks which news items have pictures. Ie which files to look for.
NancyJ
06-16-2005, 04:08 PM
It's about 3 lines of perl code to copy all files of a certain type from one directory to another. ;)
and about 30 seconds to do it in a windows gui ;) If it was that simple I wouldnt need a script :p
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.