This article mainly introduces the commonly used file operation functions in FileSystem objects. I hope the relevant knowledge and materials compiled by the editor will be helpful to you.
1. root
Function format root()
Function description returns a path string variable
Application code 'sample string = c:/intels/jingcaichunfeng/'
Public Function root()
root = Request.ServerVariables("Appl_Physical_Path")
End Function
2. url
Function format url()
Function description returns a URL string variable
Application code 'sample string = http://www.intels.net/filesys.asp'
Public Function url()
url ="http://"&Request.ServerVariables("Server_Name")
&Request.ServerVariables("Script_Name")
End Function
3. mkdir
Function format mkdir(DIrName)
Function Description Create a directory and return information
Application Code Public Function mkdir(xVar)
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FolderExists(xVar) Then
msg ="Sorry, this directory already exists!"
Else
Sys.CreateFolder(xVar)
msg ="Congratulations, the directory was created successfully! "
End If
Set Sys = Nothing
mkdir = msg
End Function
4. rmdir
Function format rmdir(DirName)
Function description deletes a directory and returns information
Application Code Public Function rmdir(xVar)
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FolderExists(xVar) Then
Sys.DeleteFolder(xVar)
msg ="Congratulations, the directory was deleted successfully!"
Else
msg ="Sorry, this directory has not been created yet!"
End If
Set Sys = Nothing
rmdir = msg
End Function
5. Isdir
Function format isdir(DirName)
Function description Checks whether a directory exists and returns information
Application Code Public Function isdir( xVar )
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FolderExists(xVar) Then
msg = True
Else
msg = False
End If
Set Sys = Nothing
isdir = msg
End Function
6. cpdir
Function format cpdir( DirName, Destination, OverWrite )
Function description Copy folder and return information
Application Code Public Function cpdir(xVar, yVar, zVar)
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FolderExists(xVar) Then
Sys.CopyFolder xVar, root&yVar, zVar
msg ="Congratulations, the directory was copied successfully!"
Else
msg ="Sorry, the directory you want was not found!"
End If
Set Sys = Nothing
cpdir = msg
End Function
7. mvdir
Function format mvdir(DirName, Destination)
Function description moves a folder and returns information
Application Code Public Function mvdir(xVar, yVar)
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FolderExists(xVar) Then
Sys.MoveFolder xVar, root&yVar
msg ="Congratulations, the directory folder has been moved!"
Else
msg ="Sorry, the directory you want was not found!"
End If
Set Sys = Nothing
mvdir = msg
End Function
8. isfile
Function format isfile( FileName )
Function description checks whether the file exists and returns information
Application Code Public Function isfile( xVar )
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FileExists(xVar) Then
msg = True
Else
msg = False
End If
Set Sys = Nothing
isfile = msg
End Function
9. wfile
Function format wfile( FileName, OverWrite, String)
Function description write string to a file and return information
Application Code Public Function wfile(xVar, yVar, zVar)
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If yVar Then
Set Txt = Sys.OpenTextFile(xVar, 2)
Txt.Write( zVar )
Txt.Close
msg ="Congratulations, the file was created successfully and saved!"
Else
If Sys.FileExists(xVar) Then
msg ="Sorry, the file already exists!"
End If
Set Sys = Nothing
wfile = msg
End Function
10. rfile
Function format rfile( FileName )
Function description reads a file and returns information
Application Code Public Function rfile(xVar)
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FileExists(xVar) Then
Set Txt = Sys.OpenTextFile(xVar, 1 )
msg = Txt.ReadAll
Txt.Close
Else
msg ="Sorry, the file does not exist!"
End If
Set Sys = Nothing
rfile = msg
End Function
11. afile
Function format afile( FileName, String)
Function description add string to a file and return information
Application Code Public Function afile(xVar, zVar)
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FileExists(xVar) Then
Set Txt = Sys.OpenTextFile(xVar, 8)
Txt.Write( zVar )
Txt.Close
msg ="Congratulations, the file was added successfully and saved!"
Else
msg ="Sorry, the file does not exist!"
End If
Set Sys = Nothing
afile = msg
End Function
12. cpfile
Function format cpfile( FileName, Destination, OverWrite)
Function Description Copy a file and return information
Application Code Public Function cpfile(xVar, yVar, zVar)
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FileExists(xVar) Then
Sys.CopyFile xVar, root&yVar, zVar
msg ="Congratulations, the file was copied successfully!"
Else
msg ="Sorry, the file copy failed!"
End If
Set Sys = Nothing
cpfile = msg
End Function
13. mvfile
Function format mvfile( FileName, Destination)
Function description moves a file and returns information
Application Code Public Function mvfile(xVar, yVar)
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FileExists(xVar) Then
Sys.MoveFile xVar, root&yVar
msg ="Congratulations, the file was moved successfully!"
Else
msg ="Sorry, the file move failed!"
End If
Set Sys = Nothing
mvfile = msg
End Function
14. rmfile
Function format rmfile( FileName )
Function description deletes a file and returns information
Application Code Public Function rmfile(xVar)
Set Sys = Server.CreateObject("Scripting.FileSystemObject")
If Sys.FileExists(xVar) Then
Sys.DeleteFile(xVar)
msg ="Congratulations, the file was deleted successfully!"
Else
msg ="Sorry, the file deletion failed!"
End If
Set Sys = Nothing
rmfile = msg
End Function
The above is an introduction to the commonly used file operation functions in FileSystem objects. I hope the relevant knowledge and materials compiled by the editor will be helpful to you. For more content, please continue to pay attention to the website of the Wrong New Technology Channel!