Web Hosting Talk







View Full Version : control panel


rajiv
07-30-2001, 03:40 PM
Creating and Removing Directories
There may come a time where you will need to dynamically create and remove directories. Fortunately, the Filesystem Object makes entire drives, folders, and files accessible to you via ASP. First of all, let's see what we'll need to make this possible. You'll need permissions on the parent directory set to allow the IUSR_machinename to create the directory. This means that the IUSR will need to be given NTFS Change permissions. Without this, your script will fail. Now for the scripting. You'll need to instanciate the filesystem object:
<% set fs=createobject("scripting.filesystemobject") %>

Next, we'll want to set a path for the new folder. I've hard-coded it here, but remember this can also be passed dynamically through a form or querystring.

<% MyFolder=server.mappath("/download/incoming/") %>

Before actually creating the folder, we should check to see if the folder already exists, and if it doesn't, then we will create the new folder.

<%
If NOT fs.folderexists(MyFolder) then
fs.createfolder(MyFolder)
End If
%>

There! That was simple! We can now check to see if the folder is there and display a message telling us whether or not the operation was successful:
<%
If fs.folderexists(MyFolder) then
response.write "Folder created successfully!"
Else
response.write "There has been an error."
End If
%>

Now, let's assume we no longer need that folder. First we'll check to make sure it exists, then we will delete the folder.
<%
set remdir=fs.getfolder(myfolder)
remdir.delete
set remdir=nothing
'-- now we'll test to see if the folder has in fact been removed
If NOT fs.folderexists(myfolder) then
response.write "Folder deleted"
Else
response.write "Folder still exists! hmmm..."
End If
%>

Similarly, you can use the filesystem object to move or copy folders and files, and even browse entire drives. Remember, however, that once you start moving files and folders around (or perform anything that writes to the server), you'll need Change permissions for the IUSR for the appropriate folder(s). Once you've got that, however, you'll be able to fully manipulate your folders and files using ASP. Cool!

Alan - Vox
07-30-2001, 03:44 PM
intersting post for the advertising section lol

chuckt101
07-30-2001, 04:03 PM
yeah.. and interesting set of urls you got there!

do you own classicworld.com too? how about classicsites, and even classiccocacola :D