At this point, you may have a good understanding of FSO. Let's take a deeper look at it to solve more complex problems.
First, you may want to rename the file. To keep track of all documents, you will want to rename them to be unique so that they can be easily region-friendly by the system
Don't. Unfortunately, FSO does not allow simple file name change 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, and we can perform 2 steps at a time. First, open the file and read the contents of the file. Suppose you want to create one here
A unique folder and a unique file to store articles. However, because the path to the folder will change every day, it is necessary to first check whether the folder has already
exists, if not, create it. This is done in the if not fso.folderexists snippet. Then, take that path and create a new file. new
After the file is created, delete the old file, which is done through fso.DeleteFile.
These 2 steps are: rename the file and then move it to a more suitable directory. Note that you can also do more operations on files here, such as writing
Edit the content before entering a new file.