After operating the drive, you will then operate the folder. These include: extracting folder information, creating folders, deleting folders, copying folders, moving folders, etc. Let’s take a look at it in detail below.
1. fso.GetFolder
You can see at a glance that it is extracting the folder. So which folder should I extract? The path to a folder must be followed. After extracting it, let’s display the relevant information of the folder? Is there any need to be extracted specifically? So, look at the program:
1, getfldr.asp
<% Set fso = CreateObject("Scripting.FileSystemObject") Set fldr = fso.GetFolder("c:/Program Files") Response.Write "The 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 the root folder" & "<br>" End If Response.Write "Drive name is: " & fldr.Drive & "<br>" %> |
First, establishing a connection to the FSO component is essential, and then Set fldr = fso.GetFolder("c:/Program Files") sets the fldr object to be assigned to the following program.
fldr.IsRootFolder is to determine whether the folder is a folder, and the value is a boolean value (true or false); fldr.Drive displays the drive letter where the folder is located.
2. fso.CreateFolder
What is more exciting is that you can create folders through ASP, where you can create folders anywhere within your authority.
2, creatfldr.asp
<% Set fso = CreateObject("Scripting.FileSystemObject") fso.CreateFolder ("c:/cnbruce") Response.Write "Folder Name" & fso.GetBaseName("c:/cnbruce") %> |
When executing the program, you should find that there is a cnbruce folder in the C drive, and fso.GetBaseName is the extracting folder name.
3. fso.DeleteFolder
A folder can be created through ASP, and folders can also be deleted.
3, delfldr.asp
<% Set fso = CreateObject("Scripting.FileSystemObject") fso.DeleteFolder("c:/cnbruce") Response.Write "Folder Deleted" %> |
I found that the newly created cnbruce folder has indeed been deleted.
Note that sometimes you need to delete a folder, and the folder does not exist, a program logical error will 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("cnbruce folder has been deleted") else fso.CreateFolder(dir) response.write("cnbruce folder has been created") end if %> |
Then, we will use a general program to adapt flexibly.