In ASP, FSO means File System Object, which is a file system object. The computer file system we are going to manipulate, here it refers to being located on the web server. So, make sure you have the right permissions for this. Ideally, you can set up a web server on your own machine so that you can easily perform testing. If running on Windows platform, try Microsoft's web server iis.
FSO Model Objects
Drive Object: Drive objects for accessing disks or network drives
FileSystemObject Object: File system objects for accessing the computer's file system
Folder Object: Folder object for accessing all properties of a folder
TextStream Object: Text stream object for accessing file content
You can use the above objects to do anything on your computer, including sabotage activities;-( So, be careful with FSO. In a web environment, storing information is very important, such as user information, log files, etc. FSO provides a powerful and simple way to efficiently save data. FSO is powered by Microsoft, and for non-Windows systems, ASP is probably no longer available.
1. File operation, get file size
Function GetFileSize(FileName)'//Function: Get file size'//Model parameter: File name'//Return value: Successfully file size, failed to -1'//Dim fIf ReportFileStatus(FileName) = 1 ThenSet f = fso.Getfile(FileName)GetFileSize = f.SizeElseGetFileSize = -1End ifEnd Function
2. Use FSO to delete the specified file
Function deleteAFile(filespec)'//Function: File delete'//Model parameter: File name'//Return value: Success is 1, Failure is -1'//If ReportFileStatus(filespec) = 1 Thenfso.deleteFile(filespec)deleteAFile = 1ElsedeleteAFile = -1End ifEnd Function
3.FSO displays all files in the specified directory
Function ShowFileList(folderspec)'//Function: When the directory exists, all files in this directory are displayed. '//Formal parameters: Directory name'//Return value: Successfully is a file list, failed to be -1'//Dim f, f1, fc, sIf ReportFolderStatus(folderspec) = 1 ThenSet f = fso.GetFolder(folderspec)Set fc = f.FilesFor Each f1 in fcs = s & f1.names = s & "|"NextShowFileList = sElseShowFileList = -1End ifEnd Function
4. Use fso to copy the specified file
Function CopyAFile(SourceFile,DestinationFile)'//Function: The file can only be copied when the source file exists, the destination file has no effect.'//Model parameter: Source file, destination file'//Return value: Success is 1, failure is -1'//Dim MyFileIf ReportFileStatus(SourceFile) = 1 ThenSet MyFile = fso.GetFile(SourceFile)MyFile.Copy (DestinationFile)CopyAFile = 1ElseCopyAFile = -1End ifEnd Function
5. The file can only be moved when the destination file does not exist.
'Response.Write MoveAFile("f:/123/4561.exe","f:/123/4562.txt")Function MoveAFile(SourceFile,DestinationFile)'//Model parameter: Source file, Destination file'//Return value: Success is 1, Failure is -1'//If ReportFileStatus(SourceFile)=1 AndReportFileStatus(DestinationFileORPath) =-1 Thenfso.MoveFile SourceFile,DestinationFileORPathMoveAFile = 1ElseMoveAFile = -1End ifEnd Function