Click to See Complete Forum and Search --> : Using ASP to create a sub folder
ryan1boyd
03-06-2003, 04:48 AM
Hi,
I want to create a subfolder every time a new user adds themselves to my database.
At the moment the ASP script adds a bunch of fields into the access database but I want the script which does this to also create a subfolder on the server for me to store their artwork into. The subfolder will have to be named the same as the username too.
Anybody done this before or have any clue?
Thanks,
Ryan
Nicodemas
03-06-2003, 09:06 AM
Have the script that puts the user into your database call the below to execute also. Set the username of the person signing up into variable, something like strUsername. If you really want to be technical, set the variable strFolderName = strUsername
This function assumes you want to build the folder under the root directory of the web server. If you don't want that, which I'm sure you don't, change the Server.Mappath the path you want. (that's a lot of paths, eh??)
<%
Function CreateAFolder
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CreateFolder(Server.Mappath("\") & strFolderName)
Set fso = Nothing
End Function
%>
Ribeyed
03-06-2003, 09:29 AM
hi,
would just like to add to above post.
You can't create nested new folders with a single call of the CreatFolder method:
if you have \folder1\folder2\username then folder1 and folder2 must exist.
Also if the folder you are trying to create already exists then this will generate an error. To stop this you can use the FolderExists method. Bellow is Nicodemas example extended to use the FolderExists method:
<%
Function CreateAFolder
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(Server.Mappath("\") & strFolderName) then
fso.CreateFolder(Server.Mappath("\") & strFolderName)
Response.write "Folder " &strFolderName& "created successfully"
Else
Response.write "Folder " & strFolderName & "exists already"
End if
Set fso = Nothing
End Function
%>
Nicodemas
03-06-2003, 10:08 AM
Good point! Also thought of this, though. I'm not sure exactly what he wants, but you could probably cut out the response.write part of the conditional statement because the user is only signing up for a new account with his web site.
Maybe if it took them to a page that explains where all the user's content can be uploaded to, then it would be cool. But he doesn't want that to happen, well, maybe he just would cut that out and make it say something else, like..
Response.Write "Sorry, the username that you requested is in use by another member.<BR>
Please use the <B>back</B> button and try another username."
but I'm just being crabby when I say all this. It is of course, up to ryan1boyd.