File.asp

來源:互聯網
上載者:User

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(空白行數)
%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.