打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
FileSystemObject的file对象
FileSystemObject的TextStream物件 - 小瓜瓜 [首頁]
●可由GetFile來取得File物件:
Private Sub Command1_Click()
Open "c:\test.txt" For Output As #1
Print #1, "test"
Close #1

 

Dim FS As Object
Dim F As Object
Set FS = CreateObject("Scripting.FileSystemObject")
Set F = FS.GetFile("c:\test.txt")
End Sub

●File.Attributes屬性:傳回或設定檔案的屬性,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()
Dim 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
MsgBox "這不是唯讀檔"
End If
End Sub

●File.Copy方法:複製檔案

Private Sub Command1_Click()
Dim FS As Object
Dim F As Object
Set FS = CreateObject("Scripting.FileSystemObject")
Set F = FS.GetFile("c:\test.txt")
F.Copy "c:\test.bak"
End Sub

●File.DateCreated屬性:檔案建立日期

Private Sub Command1_Click()
Dim FS As Object
Dim F As Object
Set FS = CreateObject("Scripting.FileSystemObject")
Set F = FS.GetFile("c:\test.txt")
MsgBox "建立日期:" & F.DateCreated
End Sub

●File.DateLastAccessed屬性:檔案最後存取日期

Private Sub Command1_Click()
Dim FS As Object
Dim F As Object
Set FS = CreateObject("Scripting.FileSystemObject")
Set F = FS.GetFile("c:\test.txt")
MsgBox "最後存取日期:" & F.DateLastAccessed
End Sub

●File.DateLastModified屬性:檔案最後修改

Private Sub Command1_Click()
Dim FS As Object
Dim F As Object
Set FS = CreateObject("Scripting.FileSystemObject")
Set F = FS.GetFile("c:\test.txt")
MsgBox "最後修改日期:" & F.DateLastModified
End Sub

●File.Delete方法:刪除檔案

Private Sub Command1_Click()
Dim FS As Object
Dim F As Object
Set FS = CreateObject("Scripting.FileSystemObject")
Set F = FS.GetFile("c:\test.bak")
F.Delete
End Sub

●File.Drive屬性:檔案所在的磁碟位置

Private Sub Command1_Click()
Dim FS As Object
Dim F As Object
Set FS = CreateObject("Scripting.FileSystemObject")
Set F = FS.GetFile("c:\test.txt")
MsgBox "本檔案在" & F.Drive & "磁碟機"
End Sub

●File.Move方法:移動檔案或改檔名

Private Sub Command1_Click()
Dim FS As Object
Dim F As Object
Set FS = CreateObject("Scripting.FileSystemObject")
Set F = FS.GetFile("c:\test.txt")
F.Move "c:\temp\" '最後一個字元是斜線為移動位置
F.Move "c:\temp" '最後一個字元不是斜線為修改檔名
End Sub

●File.Name屬性:傳回檔名

Private Sub Command1_Click()
Dim FS As Object
Dim F As Object
Set FS = CreateObject("Scripting.FileSystemObject")
Set F = FS.GetFile("c:\test.txt")
MsgBox "本檔案是" & F.Name
End Sub

●File.ParentFolder屬性:取得所在的資料夾

●File.ParentPath屬性:取得完整的路徑

●File.ShortName屬性:取得短檔名

●File.ShortPath屬性:取得短檔名路徑

●File.Size屬性:傳回檔案大小

Private Sub Command1_Click()
Dim FS As Object
Dim F As Object
Set FS = CreateObject("Scripting.FileSystemObject")
Set F = FS.GetFile("c:\test.txt")
MsgBox F.Size & "Byte(s)"
End Sub

●File.Type屬性:傳回檔案類型

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
[转载]FileSystemObject的方法和属性_david
excel中VBA提取文件夹名称的方法
VBA入门笔记
vb读取和写入多行的txt文件
ACCESS通过VBA读取TXT不乱码(转载)
[寄存]VBS对文件文件夹操作的例子
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服