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.