Advanced ASP programming (16): Drive operations for FSO Components

Source: Internet
Author: User

FSO is as exciting and fascinating as UFOs. Of course, more is also a matter of joy and sorrow. June does not see a space service provider's advertisement: MB space is only 60 RMB/year, supports database, what is supported ...... FSO is not supported. So what exactly is FSO, how powerful is it, and how it operates? This is a thorough understanding.

FSO is short for FileSystemObject. The FSO component can be used to process drives, folders, and files.

It can detect and display information distribution of the system drive, create, change, move, and delete folders, and detect the existence of some specified folders, the folder information can also be extracted, such as the name, the date on which the folder was created or last modified, and so on. FSO also makes File Processing easy.

I. fso. GetDrive

Just like other components, FSO references must also be connected.

Set fso = Server. CreateObject ("Scripting. FileSystemObject ")

Note that the inside of CreateObject is no longer MSWC, but Scripting.
Then you can use fso to process the drive. For example, fso. GetDriveName extracts the drive name, and fso. GetDrive extracts the standard drive name. For example:

1, fso. asp

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

You will find that GetDriveName ("d:") is "d:", while GetDrive ("d:") is the standard "D:", so we generally writeFso. GetDrive (fso. GetDriveName (drvPath ))To extract a specific drive disk.

Ii. drv. GetInfo
The above has extracted a specific drive, then whether to extract the specific information of the drive disk.

2. drv. asp

<%
Set fso = Server. CreateObject ("Scripting. FileSystemObject ")
Set drv = fso. GetDrive (fso. GetDriveName ("d :"))
%>
Disk Space: <% = drv. TotalSize %> <br>
Remaining disk space: <% = drv. FreeSpace %>

The above is just the information of the D Drive. Use a common function to test your own driver separately.

3. drvinfo. asp

<%
Function ShowDriveInfo (drvPath)
Dim fso, drv, s
Set fso = CreateObject ("Scripting. FileSystemObject ")
Set drv = fso. GetDrive (fso. GetDriveName (drvPath ))
S = "drive disk" & drv & "is marked :"
S = s & drv. VolumeName & "<br>"
S = s & "total space:" & drv. TotalSize & "<br>"
S = s & "available 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>

The drv. TotalSize and drv. FreeSpace return the number of bytes, which can be processed using the FormatNumber () function. For example, FormatNumber (Drive. TotalSize/, 0) can be used to obtain the disk GB at a glance.

Another file type is drv. when DriveType is the most, the value "2" is displayed. In fact, "2" indicates the "Hard Drive", and "1" indicates the "floppy disk drive ", "4" indicates "Disc Drive "......

Next we will use a program to traverse and display the information of all the drives on our machine.

4. showall. asp

<%
Function tran (Driver)
Select Case Driver
Case 0: tran = "unable to recognize devices"
Case 1: tran = "floppy disk drive"
Case 2: tran = "Hard Drive"
Case 3: tran = "Network hard drive"
Case 4: tran = "Disc Drive"
Case 5: tran = "RAM Virtual Disk"
End Select
End Function
Set fso = Server. CreateObject ("Scripting. FileSystemObject ")
%>

<Table border = 1 width = "100%">
<Tr>
<Td> drive letter </td>
<Td> type </td>
<Td> volume label </td>
<Td> total size </td>
<Td> available space </td>
<Td> File System </td>
<Td> serial number </td>
<Td> 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

Well, isn't it awesome? Then you can debug your machine and upload it to your own space for debugging. You will find that you have made some settings in the service Chamber :)
Of course, even more powerful, such as folder and file operations (including adding, modifying, and deleting ). Ps: You cannot easily add or delete the drive :)

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.