ASP programming introduction (sevente): FSO components folder operation

xiaoxiao2021-03-06  37

Operate the driver, then it is to operate the folder. These include: extract folder information, create folders, delete folders, copy folders, mobile folders, etc. The following is specifically. First, Fso.Getfolder understands that it is the extraction folder. Is that specific to extract which folder? Behind it is definitely the path to a folder. Apply the folder related information again? Is there a specific extraction. 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 & "
" if Fldr. IsRootFolder = true thrite.write "This folder" & "
" Else Response.write "This folder is not root folder" & "
" End ifresponse.write "drive name is : "& Fldr.drive &"
"%>

The connection to establish an FSO component is essential, then set fldr = fso.getFolder ("C: / Program Files") Sets the FLDR object to be assigned to make a reference to the following programs. FLDR.ISRootfolder is to determine if the folder is a folder, the value is a true or false; FLDR.DRIVE displays the drive letter in the folder. Second, fso.createfolder is more exciting to establish a folder through the ASP, you can establish any folder anywhere within your power. 2, Creatfldr.asp

<% Set fso = createObject ("scripting.filesystemObject") fso.createfolder ("c: / cnbruce") response.write "folder name" & fso.getBaseName ("c: / cnbruce")%>

The execution program should be found that the C disk has a multi-CNBRUCE folder, and fso.getBaseName is the extraction folder name. Third, Fso.Deletefolder can establish a folder through the ASP, or the folder can also be deleted. 3, Delfldr.asp

<% Set fso = createObject ("scripting.filesystemObject") fso.deletefolder ("c: / cnbruce") response.write folder has been removed "%>

It is found that the original CNBRUCE folder is indeed deleted. Note that sometimes you need to delete the folder, and the program logic error occurs when the folder does not exist. The status of the folder should be judged first.

<% dir = server.mappath ("cnbruce") set fso = createObject ("scripting.filesystemObject") IF (Fso.FoldRexists (DIR)) Thenfso.Deletefolder (Dir) Response.write ("CNBRUCE folder has been deleted") Elsefso.createFolder (Dir) Response.write ("CNBRUCE folder has been established") end if%> The following uses a general program to flexibly strain. 4, mainflr.asp

<% Sub CreateAFolder (file) Dim fso Set fso = CreateObject ( "Scripting.FileSystemObject") fso.CreateFolder (file) response.write "has established" & fileEnd SubSub DeleteAFolder (file) Dim fso Set fso = CreateObject ( "Scripting. FiLesystemObject ") fso.deletefolder (file) response.write has deleted" & FileEnd Sub%> "& fileEnd Sub%> <% Subname = Request.form (" Submit ") Create = Request.form (" Create ") DEL = Request.form (" Del ") if Subname <>" "" "" & Create & ") End IF Del <>" "" "" "& delity" "" & delate ") end if%>


It should be noted that: Deleting does not prompt "Confirm to put into the recycle bin". This requires careful handling, especially for your system folder. Fourth, the main role of fso.movefolder is the movement of the folder, which is equivalent to cutting and paste actions. 5, Movefldr.asp

<% Set fso = createObject ("scripting.filesystemObject") fso.createfolder ("c: / cnbruce") fso.movefolder "c: / cnbruce", "c: / program files /"%> Viewing the CNBRUCE folder There is no mobile format: fso.movefolder" Moved folder "," Move to folder "This program first created a CNBRUCE file under the C Clip, then move it below the C: / Program Files / folder. However, it is also necessary to pay attention to your system folder can't move. 5. The main role of fso.copyfolder: copy the folder from a certain location to another. 6, Copyfldr.asp

<% Set fso = createObject ("scripting.filesystemObject") fso.copyfolder "c: / program files / cnbruce", "C: /"%> Viewing CNBRUCE folder no copy Come over

The program is based on the execution result of the last MoveFldr.asp to complete the copy to the root directory of the C drive. (The words are longer -_-!) Of course, its copy is also included in the folder, so the subfolders and files are all copied. Let's finally delete the C: / Program Files / CNBruce and C: / CNBruce two folders. However, continue to remind you: Don't write wrong, such as writing into C: / Program Files, then you are miserable: This is called life, learn ASP to play. It's almost the same as the operation of the folder, is it a lot to use? Some of the jokes: Good things are the double-edged sword. Justice and evil are only one line, pay attention to the regular reasonable use of the component. However, there is still that you can rest assured that the website space service provider has already killed this power, and you will not bubbly, you will not bubbly :) Then then it is more subtle: FSO's operation .

转载请注明原文地址:https://www.9cbs.com/read-70349.html

New Post(0)