File.asp

File.asp

<%
Option Explicit
'-----FSO对象-----
Dim fs,ts,path
path=Request.ServerVariables("PATH_TRANSLATED")
path=Left(path,Len(path)-8)
Set fs=Server.CreateObject("Scripting.FileSystemObject")
'TextStream=FileObject.CreateTextFile(FileName,OverWrite,Unicode(true)OrASC(false))
Set ts=fs.CreateTextFile(path & "test.txt",True,False)
'TextStream=FileObject.OpenTextFile(FileName,IOMode,Create,Format)
'IOMode:1-只读,2-可写,8-追加
'Format:-1-Unicode,0-ASCII,-2-原先格式
Set ts=fs.OpenTextFile(path & "test.txt",1,True,0)
'FileObject.CopyFile source,destination,overwrite
fs.CopyFile path & "test.txt",path & "testCopy.txt",True
fs.CopyFile path & "test.txt",path & "testCopy2.txt",True
'FileObject.DeleteFile FileName,Flag(是否删只读文件)
fs.DeleteFile path & "testCopy2.txt",True
'FileObject.FileExists(FileName)
Response.Write(fs.FileExists(path & "test.txt"))
Response.Write(fs.GetExtensionName(path & "test.txt"))
Response.Write(fs.GetFile(path & "test.txt"))
Response.Write(fs.GetFileName(path & "test.txt"))
fs.MoveFile path & "testCopy.txt",path & "testCopy.txt"
'FileObject.CopyFolder Source,Destination,Overwrite
'FileObject.MoveFolder Source,Destination
'FileObject.CreateFolder(FolderName) 若目录已存在则会发生错误
'FileObject.DeleteFolder FolderName,Flag(是否删只读)
'FileObject.FolderExists(FolderName)
Response.Write(fs.GetFolder(path))
Response.Write(fs.GetParentFolderName(path))
'WindowsFolder:0 SystemFolder:1 TemporaryFolder:2
Response.Write(fs.GetSpecialFolder(0))
Response.Write(fs.GetTempName)
Response.Write(fs.GetDrive("C:"))
Response.Write(fs.GetDriveName(path))
Response.Write(fs.DriveExists("G:"))
Dim drive
For Each drive in fs.Drives 
    Response.Write(fs.GetDriveName(drive))
Next
Response.Write("E盘当前的目录是" & fs.GetAbsolutePathName(path))
Response.Write("路径的上一级是" & fs.GetAbsolutePathName(path & ".."))
Response.Write("路径下的子目录" & fs.GetAbsolutePathName(path & "test"))
'返回不包括扩展名的文件名
Response.Write(fs.GetBaseName(path & "test.txt"))

'-----TextStream 对象-----
Set ts=fs.OpenTextFile(path & "test.txt",2,True,0)
ts.Write "I am a good boy." & vbCrLf & "How are you?"
Set ts=fs.OpenTextFile(path & "test.txt",1,True,0)
Do While NOT ts.AtEndOfLine 
    Response.Write(ts.Read(1))
Loop
Do While Not ts.AtEndOfStream 
    Response.Write(ts.ReadLine)
Loop
Response.Write("现在文件指针在第" & ts.Column & "列")
Response.Write "现在文件指针在第" & ts.Line & "行"
ts.Close
Set ts=fs.OpenTextFile(path & "test.txt",1,True,0)
Response.Write(ts.ReadAll)
Set ts=fs.OpenTextFile(path & "test.txt",1,True,0)
ts.Skip(5)
Response.Write(ts.Read(1))
ts.SkipLine
Response.Write(ts.Read(1))
'ts.WriteBlankLines(空白行数)
%>

你可能感兴趣的:(File)