Introduction to ASP Programming (1): Operation of the FSO component drive

Source: Internet
Author: User

FSO, as exciting as the UFO, fascinating, of course, more people are happy to let people worry. You do not see a space service provider advertising: 100MB space as long as 60rmb/years, supporting the database, support what what ... A question does not support FSO, immediately discouraged. What is the FSO, and how great is its power, and how is the principle of its operation? Here's a thorough understanding.

First of all, FSO is the abbreviation of FileSystemObject. Of course, it is also known as the FSO component, which can be used to work with drives, folders, and files.

It detects and displays the information distribution of the system drives, and can create, change, move, and delete folders, detect if a given folder exists, and, if so, extract information about the folder, such as name, date created or last modified, and so on. The FSO also makes it easy to process files.

First, FSO. Getdrive

As with the creation of other components, the FSO reference must also establish a connection.

Set fso=server.createobject ("Scripting.FileSystemObject")

Note that the interior of the CreateObject is no longer MSWC, but scripting.

The following can be used to handle the drive through the FSO. Like the FSO. GetDriveName Extract drive name, FSO. Getdrive also extracts standard drive names. Like what:

1,fso.asp

<%Set fso=Server.CreateObject("Scripting.FileSystemObject")%>
<%=fso.GetDriveName("d:")%><br>
<%=fso.GetDrive("d:")%>

You will find that GetDriveName ("D:") is "D:" and Getdrive ("D:") is the standard "D:", so we generally write the FSO. Getdrive (FSO. GetDriveName (Drvpath)) to extract a specific drive disk.

Second, DRV. GetInfo

A particular drive has been extracted, and then it is not the specific information that is extracted from the drive.

2,drv.asp

<%
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set drv=fso.GetDrive(fso.GetDriveName("d:"))
%>
The space size of the disk: <%=drv. Totalsize%><br>

The remaining space size of the disk: <%=drv. Freespace%>

The above only extracts the information of the D disk drive, to a common function, continue to test their own driver.

3,drvinfo.asp

<%
Function ShowDriveInfo(drvPath)
Dim fso, drv, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set drv = fso.GetDrive(fso.GetDriveName(drvPath))
s = "驱动盘" & drv & "的卷标是:"
s = s & drv.VolumeName & "<br>"
s = s & "总计空间:" & drv.TotalSize & "<br>"
s = s & "剩余空间:" & drv.FreeSpace & "<br>"
s = s & "文件类型:" & drv.DriveType & "<br>"
s = s & "文件系统:" & drv.FileSystem
Response.Write s
End Function
%>
<%
on error resume next
whatpath=request.form("path")
if whatpath<>"" then
ShowDriveInfo(whatpath)
end if%>
<form action="drvinfo.asp" method="post">
<input name="path">
<input type="submit">
</form>

One of the DRV. TotalSize and Drv.freespace return the number of bytes, which we can use with the FormatNumber () function. For example, FormatNumber (drive.totalsize/1024,0) Gets a glimpse of how much disk G is worth.

There is also a file type: DRV. DriveType The most time is to display the value "2", in fact, "2" means "hard drive", "1" means "floppy disk drive", "4" means "optical drive" ...

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.