Example Description: fso File Processing by asp

Source: Internet
Author: User

Hello everyone, I am a 3 Bird. Remember my previous article! For more information about common fso methods, I would like to review the above article and read the following!

1. the previous article talked about the usage of some common fso methods. This time, we will use examples to illustrate it, similar to fso's powerful functions for file processing. let's take a look at the following!

<%
Set fso = Server. CreateObject ("Scripting. FileSystemObject ")
Set fout = fso. CreateTextFile (server. mappath ("test.txt "))
Fout. WriteLine ("Media China www.cn-media.com ")
Fso. copyfile "D: \ 6-17 \ wwwroot \ test.txt", "D: \ 6-17 \ wwwroot \ test1.txt"
%>

 

Before execution, you will see that a test.txt file is created, and a test1.txt file is copied. Do you see the above? We have an additional method for uploading files, but it is not the copyfile method. Next, I will explain how to operate related files.

Copyfile: This method Copies files. You can use wildcards to copy multiple files at a time point.
Movefile: This method moves the file.
Deletefile; this method is used to delete the specified file.

Note: before using the preceding method, you must first create a filesystemobject object example. Here is a complete example!

<%
Set fso = Server. CreateObject ("Scripting. FileSystemObject ")
Set fout = fso. CreateTextFile (server. mappath ("test.txt "))
Fout. WriteLine ("Media China www.cn-media.com ")
Fso. copyfile "D: \ 6-17 \ wwwroot \ test.txt", "D: \ 6-17 \ wwwroot \ test1.txt"
'Copy an object
Fso. movefile "D: \ 6-17 \ wwwroot \ test.txt", "D: \ 6-17 \ wwwroot \ test3.txt"
Move files
Fso. deletefile "D: \ 6-17 \ wwwroot \ test.txt"
Fso. deletefile "D: \ 6-17 \ wwwroot \ test3.txt"
Delete an object

%>
 

After reading the above, I believe everyone understands how to use the fso operation file. Of course, the above is only one method, and other operations can also be completed. Haha!

2. Let's learn how to create a folder. The file will be created, the file operation will be performed, and the folder will not be created. What's the problem, right? Come with me!

<%

'Create a FileSystemObject object example
Set MyFileObject = Server. CreateObject ("Scripting. FileSystemObject ")
'Create a folder for operation
MyFileObject. CreateFolder ("C: \ NewFolder ")
'Move this folder
MyFileObject. MoveFolder "C: \ NewFolder" "C: \ NewFolder2"
'Delete this folder
MyFileObject. DeleteFolder "C: \ NewFolder2" %>

The following is a small example of personal writing: "Creating a cn-media folder"

<HTML>
<HEAD> <TITLE> folder content </TITLE> </HEAD>
<BODY>
<%
Set fso = Server. CreateObject ("Scripting. FileSystemObject ")
Fso. CreateFolder (server. mappath ("chinamedia "))
%>
</Body>
</HTML>

After reading the above, I believe everyone will do it, will it? You can check the article on folder processing. I believe everyone can do it without reading it.

3. The following describes how to use the filexists method to check whether a file exists. Let's take a look at the example below!

<%
Set fso = Server. CreateObject ("Scripting. FileSystemObject ")
If fso. fileexists ("D: \ 6-17 \ wwwroot \ test.txt") then
Response. write ("this file exists ")
Else
Response. write ("this file does not exist ")
End if %>
 

Everyone will do it. The above example is very intuitive. Haha!

4. Next we will introduce a special feature in fso, that is, display the file attributes. Let's look down!

<%
'You must create an instance before using it. You can understand it!
Set fso = Server. CreateObject ("Scripting. FileSystemObject ")
Set fut = fso. getfile ("D: \ 6-17 \ wwwroot \ test.txt ")
%>
<Br> name: <% = fut. name %> |
<Br> path: <% = fut. path %>
<Br> drive letter: <% = fut. drive %>
<Br> size: <% = fut. size %>
<Br> type: <% = fut. type %>
<Br> attribute: <% = fut. attributes %>
<Br> creation date: <% = fut. datecreated %>
 

Let's take a look at the following execution results. I believe you have read them.
Name: test.txt
Path: D: \ 6-17 \ wwwroot \ test.txt
Drive letter: D:
Size: 26
Type: Text Document
Property: 32
Created on: 15:06:02
 

5. The following example shows how to use fso to operate the drive.

<%
'You must create an instance before using it. You can understand it!
Set fso = Server. CreateObject ("Scripting. FileSystemObject ")
For each thing in fso. drives
%>
<Br> drive letter: <% = thing. driveletter %>
<Br> total drive size: <% = thing. totalsize %>
<Br> available drive capacity: <% = thing. availablespace %> <br>
<Hr> <% next %>
 

Let's show you the execution result interface.

Drive letter: C
Drive size: 9992126464
Drive capacity: 233447424

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.