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
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)) The volume label of s = "Drive Disk" & DRV & "is:" s = S & DRV. VolumeName & "<br>" s = S & "Total space:" & DRV. TotalSize & "<br>" s = S & "remaining space:" & DRV. FreeSpace & "<br>" s = S & "file type:" & DRV. DriveType & "<br>" s = S & "file system:" & 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" ...
The following is a program that iterates through all the drives on your machine.
4,showall.asp
<% Function Tran (Driver) Select Case Driver Case 0:tran= "Device Unrecognized" Case 1:tran= "Floppy disk drive" Case 2:tran= "Hard drive" Case 3:tran= "Network hard Drive" Case 4:tran= "Optical drive" Case 5:tran= "Ram Virtual Disk" End Select End Function Set Fso=server.createobject ("Scripting.FileSystemObject") %>
<table border=1 width= "100%" > <tr> <td> Letter </td> <td> type </td> <td> Volume label </td> <td> Total size </td> <td> Free Space </td> <td> File System </td> <td> Serial Number </td> <td> is available </td> <td> Path </td> </tr> <% On Error Resume Next For each DRV in FSO. Drives Response.Write "<tr>" Response.Write "<td>" & DRV. DriveLetter & "</td>" Response.Write "<td>" & Tran (DRV. DriveType) & "</td>" Response.Write "<td>" & DRV. VolumeName & "</td>" Response.Write "<td>" & FormatNumber (DRV. totalsize/1024, 0 & "</td>" Response.Write "<td>" & FormatNumber (DRV. availablespace/1024, 0 & "</td>" Response.Write "<td>" & DRV. FileSystem & "</td>" Response.Write "<td>" & DRV. SerialNumber & "</td>" Response.Write "<td>" & DRV. IsReady & "</td>" Response.Write "<td>" & DRV. Path & "</td>" Response.Write "</tr>" Next Set fs=nothing %> </table>
|
Http://www.cnbruce.com/code/showall.asp
Yes, isn't it nice? Then you can debug your own machine, then upload to your own space to debug, you will find the service chamber you have made some settings:
Of course, the more God is still in the back, such as the folder, the operation of the file (including add, modify and delete). PS: You are not easy to add delete to the drive: