What are the file manipulation functions commonly used in filesystem objects? _asp Foundation

Source: Internet
Author: User
Tags file copy mkdir servervariables
What are the file manipulation functions commonly used in filesystem objects?
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)
Feature description Create a directory and return information
Apply Code public Function mkdir (Xvar)
Set Sys = Server.CreateObject ("Scripting.FileSystemObject")
If sys.folderexists (Xvar) Then
msg = "Sorry, the directory already exists!" "
Else
Sys.createfolder (Xvar)
msg = "Congratulations, Directory creation success!" "
End If
Set Sys = Nothing
mkdir = Msg
End Function

4, RmDir
function format rmdir (dirname)
Feature description Delete a directory and return information
Apply Code public Function rmdir (Xvar)
Set Sys = Server.CreateObject ("Scripting.FileSystemObject")
If sys.folderexists (Xvar) Then
Sys.deletefolder (Xvar)
msg = "Congratulations, directory deletion successful!"
Else
msg = "Sorry, this directory has not yet been created!" "
End If
Set Sys = Nothing
RmDir = Msg
End Function

5, Isdir
function Format Isdir (dirname)
Feature description checks whether a directory exists and returns information
Apply 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)
Feature Description Copy folder and return information
Apply 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, directory replication success!"
Else
msg = "Sorry, did not find the directory you want!"
End If
Set Sys = Nothing
Cpdir = Msg
End Function

7, Mvdir
function Format Mvdir (dirname, destination)
Feature description move a folder and return information
Apply Code public Function Mvdir (Xvar, Yvar)
Set Sys = Server.CreateObject ("Scripting.FileSystemObject")
If sys.folderexists (Xvar) Then
Sys.movefolder Xvar, Root&yvar
msg = "Congratulations, folder has been moved!"
Else
msg = "Sorry, did not find the directory you want!"
End If
Set Sys = Nothing
Mvdir = Msg
End Function

8, Isfile
function format isfile (FileName)
Feature description Check if file exists and return information
Apply 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)
Feature description writes a string to a file and returns information
Apply 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, file creation successful and save!"
Else
If sys.fileexists (Xvar) Then
msg = "Sorry, file already exists!"
End If
Set Sys = Nothing
Wfile = Msg
End Function

10, Rfile
function Format Rfile (FileName)
Feature description read a file and return information
Apply 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, file does not exist!"
End If
Set Sys = Nothing
Rfile = Msg
End Function

11, Afile
function Format Afile (FileName, String)
Feature description Add a string to a file and return information
Apply 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, file added successfully and saved!"
Else
msg = "Sorry, file does not exist!"
End If
Set Sys = Nothing
Afile = Msg
End Function

12, Cpfile
function Format cpfile (FileName, Destination, OverWrite)
Feature description Copy a file and return information
Apply 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, file copy successful!"
Else
msg = "Sorry, file copy failed!"
End If
Set Sys = Nothing
Cpfile = Msg
End Function

13, Mvfile
function Format mvfile (FileName, destination)
Feature description move a file and return information
Apply Code public Function mvfile (Xvar, Yvar)
Set Sys = Server.CreateObject ("Scripting.FileSystemObject")
If sys.fileexists (Xvar) Then
Sys.movefile Xvar, Root&yvar
msg = "Congratulations, file move successful!"
Else
msg = "Sorry, file move failed!"
End If
Set Sys = Nothing
Mvfile = Msg
End Function

14, Rmfile
function Format Rmfile (FileName)
Feature description Delete a file and return information
Apply Code public Function Rmfile (Xvar)
Set Sys = Server.CreateObject ("Scripting.FileSystemObject")
If sys.fileexists (Xvar) Then
Sys.deletefile (Xvar)
msg = "Congratulations, file deletion successful!"
Else
msg = "Sorry, file deletion failed!"
End If
Set Sys = Nothing
Rmfile = Msg
End Function

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.