Introduction to ASP Programming (17): FSO component's folder Operation _asp Foundation

Source: Internet
Author: User
After the drive is finished, the folder is then manipulated. These include extracting folder information, creating folders, deleting folders, copying folders, moving folders, and so on. Here's a concrete look.

first, FSO. GetFolder
A look is clear, is the extraction folder. Which folder is that specifically extracted? Definitely follow the path to a folder. Extract it and then display the information about the folder? Whether there is to be specific extraction down. So, look at the program:
1,getfldr.asp


<%
Set fso = CreateObject ("Scripting.FileSystemObject")
Set Fldr = fso. GetFolder ("C:\Program Files")
Response.Write "Parent folder name is:" & Fldr & "<br>"

If Fldr. IsRootFolder = True Then
Response.Write "This folder is a folder" & "<br>"
Else
Response.Write "This folder is not a root folder" & "<br>"
End If

Response.Write "Drive name is:" & Fldr. Drive & "<br>"
%>


It is essential to establish a connection to the FSO component first, and then Set Fldr = fso. GetFolder ("C:\Program Files")Set the Fldr object to be assigned as a reference to the following program.

Fldr. IsRootFolderThe value is a Boolean (true or FALSE) to determine if the folder is a folder; Fldr. DriveThe drive letter of the folder is displayed.

Second, FSO. CreateFolder
The next more exciting is the creation of a folder through ASP, you can create any folder within your jurisdiction.
2,creatfldr.asp


<%
Set fso = CreateObject ("Scripting.FileSystemObject")
Fso. CreateFolder ("C:\cnbruce")
Response.Write "folder name is" & FSO. Getbasename ("C:\cnbruce")
%>


Execution procedures, should find C disk more out of the Cnbruce folder, FSO. Getbasename is the extraction folder name.

third, FSO. DeleteFolder
You can create a folder from ASP, and you can also delete the folder.

3,delfldr.asp


<%
Set fso = CreateObject ("Scripting.FileSystemObject")
Fso. DeleteFolder ("C:\cnbruce")
Response.Write "folder deleted"
%>



It is found that the Cnbruce folder that you just created has actually been deleted.

Note that there are times when you need to delete a folder, and a program logic error occurs when the folder does not exist. You should first determine the status of the folder.



<%
Dir=server.mappath ("Cnbruce")
Set fso = CreateObject ("Scripting.FileSystemObject")
if (FSO). FolderExists (dir)) then
Fso. DeleteFolder (dir)
Response.Write ("Cnbruce folder has been removed")
Else
Fso. CreateFolder (dir)
Response.Write ("Cnbruce folder already established")
End If
%>



The following is a general procedure for flexible response.

4,mainflr.asp


<%
Sub Createafolder (file)
Dim FSO
Set fso = CreateObject ("Scripting.FileSystemObject")
Fso. CreateFolder (file)
Response.Write "has established" &file
End Sub

Sub Deleteafolder (file)
Dim FSO
Set fso = CreateObject ("Scripting.FileSystemObject")
Fso. DeleteFolder (file)
Response.Write "has been removed" &file
End Sub
%>
<%
Subname=request.form ("Submit")
Create=request.form ("create")
Del=request.form ("Del")
If subname<> "" Then
If create<> "" Then
Call Createafolder ("&create&")
End If
If del<> "" Then
Call Deleteafolder ("&del&")
End If
End If
%>
<form action= "mainflr.asp" method= "POST" >
<input name= "Create" >
<input type= "Submit" value= "establish" name= "submit" >
</form>
<form action= "mainflr.asp" method= "POST" >
<input name= "Del" >
<input type= "Submit" value= "Delete" name= "Submit" >
</form>


Note that deleting does not prompt "confirm that you want to put in the Recycle Bin." This is something you need to be cautious about, especially for your system folders.

four, FSO. MoveFolder
The main role is to move the folder, which is equivalent to a cut-and-paste action.

5,movefldr.asp


<%
Set fso = CreateObject ("Scripting.FileSystemObject")
Fso. CreateFolder ("C:\cnbruce")
Fso. MoveFolder "C:\cnbruce", "C:\Program files\"
%>
<a href= "C:\Program files\" > see if the Cnbruce folder has moved over </a>



Format: FSO. MoveFolder "moved folder", "moved to Folder"

This program first establishes the Cnbruce folder under C disk and then moves it below the C:\Program files\ folder.

However, it is also necessary to note that your system folders cannot be moved randomly.

Five, FSO. CopyFolder
Primary role: Copy a folder from one location to another.
6,copyfldr.asp


<%
Set fso = CreateObject ("Scripting.FileSystemObject")
Fso. CopyFolder "C:\Program files\cnbruce", "C:\"
%>
<a href= "C:\" > see if the Cnbruce folder has been copied. </a>


The program is based on the previous movefldr.asp of the implementation of the results of the completion of the copy to the C-packing directory. (the words are comparatively long-_-!)

Of course, its copy is to include the folder inside so subfolders and files are all copied.

Finally, try to delete the C:\Program Files\cnbruce and c:\cnbruce two folders.

However, continue to remind you: do not write wrong, such as written C:\Program Files, then you are miserable: this is called desperate, learning ASP play out the heartbeat out.

The operation of the folder is almost, is it more useful? There is a speech: The good thing is a double-edged sword. Justice and Evil are only a line, pay attention to the formal rational use of this component. However, you can rest assured that the site space service providers to this power has been limited to the dead, how you will not bubble up again:

Then the next step is more subtle: the FSO's operation of the file.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.