Use ASP to operate folders

Source: Internet
Author: User
Including extracting Folder Information, creating folders, deleting folders, copying folders, and moving folders. Next, let's take a look.

I. FSO. getfolder
At first glance, we can see that the folder is extracted. Which folder is extracted? Follow the path of a folder. After the information is extracted, the folder information is displayed? Is there any need to extract it. So, check the program:
1. getfldr. asp


<%
Set FSO = Createobject ("scripting. FileSystemObject ")
Set FLDR = FSO. getfolder ("C:/Program Files ")
Response. Write "parent folder name:" & FLDR & "<br>"

If FLDR. isrootfolder = true then
Response. Write "this folder is a folder" & "<br>"
Else
Response. Write "this folder is not the root folder" & "<br>"
End if

Response. Write "drive name:" & FLDR. Drive & "<br>"
%>

It is essential to establish a connection to the FSO component first, and then set FLDR = FSO. getfolder ("C:/Program Files") sets the FLDR object to be assigned a value for reference in the following program.

FLDR. isrootfolder determines whether the folder is a root folder with a Boolean value (true or false). FLDR. Drive displays the drive letter of the folder.

Ii. FSO. createfolder
The following is an exciting example of creating folders through ASP. You can create any folder anywhere in your power.
2. creatfldr. asp


<%
Set FSO = Createobject ("scripting. FileSystemObject ")
FSO. createfolder ("C:/cnbruce ")
Response. Write "folder name" & FSO. getbasename ("C:/cnbruce ")
%>

Execute the program and you should find that the C drive has an additional cnbruce folder, and FSO. getbasename is the extraction folder name.

Iii. FSO. deletefolder
You can use ASP to create a folder and delete the folder.

3. delfldr. asp


<%
Set FSO = Createobject ("scripting. FileSystemObject ")
FSO. deletefolder ("C:/cnbruce ")
Response. Write "folder deleted"
%>

The created cnbruce folder is indeed deleted.
 
Next we will adopt a general program to flexibly adapt to the situation.

4, mainflr. asp


<%
Sub createafolder (file)
Dim FSO
Set FSO = Createobject ("scripting. FileSystemObject ")
FSO. createfolder (file)
Response. Write "created" & file
End sub

Sub deleteafolder (file)
Dim FSO
Set FSO = Createobject ("scripting. FileSystemObject ")
FSO. deletefolder (file)
Response. Write "deleted" & 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 = "CREATE" name = "Submit">
</Form>
<HR>
<Form action = "mainflr. asp" method = "Post">
<Input name = "Del">
<Input type = "Submit" value = "delete" name = "Submit">
</Form>

Note that the deletion does not prompt "confirm to be placed in the recycle bin. This requires careful processing, especially for your system folders.

Iv. FSO. movefolder
The main function is to move folders, which is equivalent to cutting and pasting.

5. movefldr. asp


<%
Set FSO = Createobject ("scripting. FileSystemObject ")
FSO. createfolder ("C:/cnbruce ")
FSO. movefolder "C:/cnbruce", "C:/program files /"
%>
<A href = "C:/program files/"> check whether the cnbruce folder has been moved. </a>

Format: FSO. movefolder "Moved folder", "Moved folder"

In this program, the cnbruce folder is created under drive C, and then moved to the C:/program files/folder.

However, you must also note that your system folders cannot be moved randomly.

V. FSO. copyfolder
Main function: 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:/"> check whether the cnbruce folder has been copied. </a>

The program is copied to the C root directory based on the execution result of movefldr. asp. (Long -_-!)

Of course, it also copies all subfolders and files in the folder.

Finally, try to delete the C:/program files/cnbruce and C:/cnbruce folders.

However, keep reminding you: do not make mistakes, such as writing C:/program files, so you are miserable: This is called a joke, learning ASP to play out a heartbeat.

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.