The magic of FSO in ASP-using FSO for content management

Source: Internet
Author: User

Author: Gan jiping

At this point, you may already have a good understanding of FSO. Let's take further research to solve more complex problems.

First, you may want to rename the file. To track all documents, you will rename them to be unique so that they can be easily located by the system.

No. Unfortunately, FSO does not allow simple file rename operations, so we have to modify it.

<%

'Create the FSO object

Set FSO = server. Createobject ("scripting. FileSystemObject ")

Path = "C: EMP est.txt"

Strdate = Replace (date (),"/","")

Strdir = "C: inetpubwwwrootarticles" & strdate

Strnewfilename = hour (now) & "_" & minute (now )&"_"&

Second (now) & ". html"

'Open the old file

Set file = FSO. opentextfile (path, 1) <-- for reading

Strtext = file. readall

Set file = nothing

'Check for and/or create folder

If not FSO. folderexists (server. mappath (strdir) then

Set F = FSO. createfolder (server. mappath (strdir ))

Else

Set F = FSO. getfolder (server. mappath (strdir ))

End if

'Create and write new file

Set file = FSO. createtextfile (F. Path & "" & strnewfilename)

File. Write (strtext)

Set F = nothing

File. Close

Set file = nothing

'Delete the old file

FSO. deletefile (Path & "& RST (" FILENAME ") & I)

'Clean up

Set FSO = nothing

%>

The lack of FSO capabilities has become an advantage here. We can perform two steps at a time. First, open the file and read the content of the file. Suppose you want to create

Unique folder and a unique file for storageArticle. However, because the folder path changes every day, you must first check whether the folder has been

Yes. If not, create it. If not FSO. folderexistsCodeComplete. Then, obtain the path and create a new file. New

After the file is created, delete the old file, which is completed by FSO. deletefile.

the two steps are as follows: Rename the file and move it to a more appropriate directory. Note: You can also perform more operations on the file, such as editing the content before writing
the new file.

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.