After the drive is operated, the folder is operated. 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>" %> |
First, it is essential to establish a connection to the FSO component. ThenSet fldr = fso. GetFolder ("c: \ Program Files ")Set the fldr object to be assigned a value for reference in the following program.
Fldr. IsRootFolderTo determine whether the folder is a root folder, the value is Boolean (true or false );Fldr. DriveThe drive letter of the folder is displayed.
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.
Note: When you delete a folder that does not exist, a program logic error may occur. The status of the folder should be determined first.
<% Dir = server. mappath ("cnbruce ") Set fso = CreateObject ("Scripting. FileSystemObject ") If (fso. FolderExists (dir) then Fso. DeleteFolder (dir) Response. write ("The cnbruce folder has been deleted ") Else Fso. CreateFolder (dir) Response. write ("The cnbruce folder has been created ") End if %> |
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 SubSub 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.
The operations on folders are almost the same. Is it very useful? Good things are a double-edged sword. Justice and evil are only the first line. Pay attention to the regular and rational use of this component. However, you can rest assured that the website space service provider has been bound to this power, and you will not bubble up any more reasons :)
The next step is more subtle: FSO file operations.