Functions of some FSO in fso| function asp
'//================================== file Operation ==================================
' Take file size
Function GetFileSize (FileName)
'//function: Take file size
'//formal parameter: filename
'//Return Value: Success for file size, failure to-1
'//
Dim F
If reportfilestatus (FileName) = 1 Then
Set f = fso. Getfile (FileName)
GetFileSize = F.size
Else
GetFileSize =-1
End If
End Function
' File deletion
Function Deleteafile (filespec)
'//function: File deletion
'//formal parameter: filename
'//Return Value: Success is 1, failure is-1
'//
If reportfilestatus (filespec) = 1 Then
Fso.deletefile (filespec)
Deleteafile = 1
Else
Deleteafile =-1
End If
End Function
' Show file list
Function showfilelist (FOLDERSPEC)
'//function: Displays all files in this directory when the directory exists
'//formal parameter: directory name
'//Return Value: Success for file list, failed-1
'//
Dim F, F1, FC, S
If reportfolderstatus (Folderspec) = 1 Then
Set f = fso. GetFolder (FOLDERSPEC)
Set FC = F.files
For each F1 in FC
s = S & f1.name
s = S & "|"
Next
Showfilelist = S
Else
Showfilelist =-1
End If
End Function
'!!!
' File copy
Function Copyafile (Sourcefile,destinationfile)
'//function: When the source file exists, the file can be copied, the destination file has no effect
'//Parameter: source file, destination file
'//Return Value: Success is 1, failure is-1
'//
Dim MyFile
If reportfilestatus (sourcefile) = 1 Then
Set MyFile = fso. GetFile (sourcefile)
Myfile.copy (Destinationfile)
Copyafile = 1
Else
Copyafile =-1
End If
End Function
' File move
' Response.Write moveafile ("F:\123\4561.exe", "F:\123\4562.txt")
Function Moveafile (Sourcefile,destinationfile)
'//function: To move a file if the destination file does not exist when the source file exists
'//Parameter: source file, destination file
'//Return Value: Success is 1, failure is-1
'//
If reportfilestatus (sourcefile) =1 and Reportfilestatus (destinationfileorpath) =
-1 Then
Fso. MoveFile Sourcefile,destinationfileorpath
Moveafile = 1
Else
Moveafile =-1
End If
End Function
' Does the file exist?
' Response.Write reportfilestatus ("G:\soft\delphi\my_pro\ code library. exe")
Function Reportfilestatus (FileName)
'//function: To determine whether a file exists
'//formal parameter: filename
'//Return Value: Success is 1, failure is-1
'//
Dim msg
msg =-1
If (FSO). FileExists (FileName)) Then
msg = 1
Else
msg =-1
End If
Reportfilestatus = Msg
End Function
' File creation date
' Response.Write showdatecreated (' G:\soft\delphi\my_pro\ code library. exe ')
' Response.Write Showdatecreated ("G:\soft\delphi\my_pro\ complex code library. exe")
function showdatecreated (filespec)
'//feature: File creation date
'// Parameter: filename
'//Return Value: Success: File creation date, failed:-1
'//
Dim F
If reportfilestatus (filespec) = 1 Then
Set f = fso. GetFile (filespec)
showdatecreated = f.datecreated
Else
showdatecreated =-1
End If
End Function
' File Properties
' Response.Write getattributes ("G:\soft\delphi\my_pro\ complex code library. exe")
Function getattributes (FileName)
//function: Show file properties
//parameter: filename
'//Return Value: Success: File properties, failed:-1
'//
Dim f,str
If reportfilestatus (filename) = 1 Then
Set f = fso. GetFile (FileName)
Select Case F.attributes
Case 0 str= "normal file. No properties are set. "
Case 1 str=" read-only file. can read and write. "
Case 2 str=" hides the file. can read and write. "
Case 4 str=" System file. can read and write. "
Case str=" folder or directory. Read-only. "
Case str=" files that have changed since the last backup. can read and write. "
Case 1024 str=" link or shortcut. Read-only. "
Case 2048 str=" compresses the file. Read-only. "
End Select
GetAttributes = Str
Else
getattributes =-1
End If
End Function
' Last visit/Last modification time
' Response.Write showfileaccessinfo (' G:\soft\delphi\my_pro\ code library. exe ')
Function Showfileaccessinfo (Filename,infotype)
'//function: Show information when file is created
'//formal parameter: file name, information category
'//1-----creation time
'//2-----Last access time
'//3-----Last modification time
'//4-----file path
'//5-----file name
'//6-----file type
'//7-----File Size
'//8-----Parent Directory
'//9-----root directory
'//Return value: Message created successfully for file, failed:-1
'//
Dim F, S
If reportfilestatus (FileName) = 1 Then
Set f = fso. GetFile (FileName)
Select Case InfoType
Case 1 s = f.datecreated '//1-----
Creation time
Case 2 s = f.datelastaccessed '//2-----Last visit
Time
Case 3 S = f.datelastmodified '//3-----Last Modified
Time
Case 4 S = F.path '//4
-----file path
Case 5 s = F.name '//5
-----file Name
Case 6 S = F.type '//6
-----file Type
Case 7 s = f.size '//7
-----File Size
Case 8 s = F.parentfolder '//8-----
Parent Directory
Case 9 s = F.rootfolder '//8-----
root directory
End Select
Showfileaccessinfo = S
ELse
Showfileaccessinfo =-1
End If
End Function
' Write a text file
Function Writetxtfile (Filename,textstr,writeorappendtype)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim F, M
Select Case Writeorappendtype
Case 1: ' File for write operations
Set f = fso. OpenTextFile (FileName, ForWriting, True)
F.write Textstr
F.close
If reportfilestatus (FileName) = 1 Then
Writetxtfile = 1
Else
Writetxtfile =-1
End If
Case 2: ' Write at end of file
If reportfilestatus (FileName) = 1 Then
Set f = fso. OpenTextFile (FileName, ForAppending)
F.write Textstr
F.close
Writetxtfile = 1
Else
Writetxtfile =-1
End If
End Select
End Function
' Read text file
Function Readtxtfile (FileName)
Const