| FileSystemObject的TextStream物件 - 小瓜瓜 [首頁] 
 
●可由GetFile來取得File物件:
 
    
        
            | Private Sub Command1_Click()
            End Sub
            Open "c:\test.txt" For Output As #1
            Close #1Print #1, "test"    Dim FS As Object
            Dim F As Object
            Set FS = CreateObject("Scripting.FileSystemObject")
            Set F = FS.GetFile("c:\test.txt")  |  ●File.Attributes屬性:傳回或設(shè)定檔案的屬性,MSDN上的說明表如下
 
    
        
            | Normal | 0 | Normal file. No attributes are set. |  
            | ReadOnly | 1 | Read-only file. Attribute is read/write. |  
            | Hidden | 2 | Hidden file. Attribute is read/write. |  
            | System | 4 | System file. Attribute is read/write. |  
            | Volume | 8 | Disk drive volume label. Attribute is read-only. |  
            | Directory | 16 | Folder or directory. Attribute is read-only. |  
            | Archive | 32 | File has changed since last backup. Attribute is read/write. |  
            | Alias | 1024 | Link or shortcut. Attribute is read-only. |  
            | Compressed | 2048 | Compressed file. Attribute is read-only. |  
    
        
            | Private Sub Command1_Click()
            End SubDim FS As Object
            Dim F As Object
            Set FS = CreateObject("Scripting.FileSystemObject")
            Set F = FS.GetFile("c:\test.txt")
            
            If (F.Attributes And 1) = 1 Then
            MsgBox "這是唯讀檔"  
            Else
            End IfMsgBox "這不是唯讀檔"  |  ●File.Copy方法:複製檔案
 
    
        
            | Private Sub Command1_Click()
            End SubDim FS As Object
            Dim F As Object
            Set FS = CreateObject("Scripting.FileSystemObject")
            Set F = FS.GetFile("c:\test.txt")
            F.Copy "c:\test.bak"  |  ●File.DateCreated屬性:檔案建立日期
 
    
        
            | Private Sub Command1_Click()
            End SubDim FS As Object
            Dim F As Object
            Set FS = CreateObject("Scripting.FileSystemObject")
            Set F = FS.GetFile("c:\test.txt")
            MsgBox "建立日期:" & F.DateCreated  |  ●File.DateLastAccessed屬性:檔案最後存取日期
 
    
        
            | Private Sub Command1_Click()
            End SubDim FS As Object
            Dim F As Object
            Set FS = CreateObject("Scripting.FileSystemObject")
            Set F = FS.GetFile("c:\test.txt")
            MsgBox "最後存取日期:" & F.DateLastAccessed  |  ●File.DateLastModified屬性:檔案最後修改
 
    
        
            | Private Sub Command1_Click()
            End SubDim FS As Object
            Dim F As Object
            Set FS = CreateObject("Scripting.FileSystemObject")
            Set F = FS.GetFile("c:\test.txt")
            MsgBox "最後修改日期:" & F.DateLastModified  |  ●File.Delete方法:刪除檔案
 
    
        
            | Private Sub Command1_Click()
            End SubDim FS As Object
            Dim F As Object
            Set FS = CreateObject("Scripting.FileSystemObject")
            Set F = FS.GetFile("c:\test.bak")
            F.Delete  |  ●File.Drive屬性:檔案所在的磁碟位置
 
    
        
            | Private Sub Command1_Click()
            End SubDim FS As Object
            Dim F As Object
            Set FS = CreateObject("Scripting.FileSystemObject")
            Set F = FS.GetFile("c:\test.txt")
            MsgBox "本檔案在" & F.Drive & "磁碟機(jī)"  |  ●File.Move方法:移動(dòng)檔案或改檔名
 
    
        
            | Private Sub Command1_Click()
            End SubDim FS As Object
            Dim F As Object
            Set FS = CreateObject("Scripting.FileSystemObject")
            Set F = FS.GetFile("c:\test.txt")
            F.Move "c:\temp\" '最後一個(gè)字元是斜線為移動(dòng)位置
            F.Move "c:\temp" '最後一個(gè)字元不是斜線為修改檔名  |  ●File.Name屬性:傳回檔名
 
    
        
            | Private Sub Command1_Click()
            End SubDim FS As Object
            Dim F As Object
            Set FS = CreateObject("Scripting.FileSystemObject")
            Set F = FS.GetFile("c:\test.txt")
            MsgBox "本檔案是" & F.Name  |  ●File.ParentFolder屬性:取得所在的資料夾
 ●File.ParentPath屬性:取得完整的路徑
 ●File.ShortName屬性:取得短檔名
 ●File.ShortPath屬性:取得短檔名路徑
 ●File.Size屬性:傳回檔案大小
 
    
        
            | Private Sub Command1_Click()
            End SubDim FS As Object
            Dim F As Object
            Set FS = CreateObject("Scripting.FileSystemObject")
            Set F = FS.GetFile("c:\test.txt")
            MsgBox F.Size & "Byte(s)"  |  ●File.Type屬性:傳回檔案類型 |