4
A
回答
3
-1
'Getting and Setting File Attributes
Declare Function SetFileAttributes Lib "kernel32" _
Alias "SetFileAttributesA" (ByVal lpFileName As _
String, ByVal dwFileAttributes As Long) As Long
Declare Function GetFileAttributes Lib "kernel32" _
Alias "GetFileAttributesA" (ByVal lpFileName As _
String) As Long
Public Function GetAttributes(Filename As String, _
Archive As Boolean, Hidden As Boolean, _
ReadOnly As Boolean, System As Boolean)
'Dimension and setup some variables.
Dim Data As Long
Archive = False: Hidden = False: ReadOnly = False
'Get Data and check for success.
Data = GetFileAttributes(Filename)
If Data = 0 Then GetAttributes = 0 Else GetAttributes = 1
'Work out what it is.
If Data = 128 Then Exit Function
If Data - 32 >= 0 Then Archive = True: Data = Data - 32
If Data - 4 >= 0 Then System = True: Data = Data - 4
If Data - 2 >= 0 Then Hidden = True: Data = Data - 2
If Data - 1 >= 0 Then ReadOnly = True: Data = Data - 1
End Function
Public Function SetAttributes(Filename As String, _
Archive As Boolean, Hidden As Boolean, _
ReadOnly As Boolean, System As Boolean)
'Dimension a Variable.
Dim Data As Long
'Work out what Data should be.
Data = 0
If Archive = True Then Data = Data + 32
If Hidden = True Then Data = Data + 2
If ReadOnly = True Then Data = Data + 1
If System = True Then Data = Data + 4
If Data = 0 Then Data = 128
'Set the attributes and check for success.
SetAttributes = SetFileAttributes(Filename, Data)
End Function
2
使用GETATTR和SETATTR
Dim attributes As VbFileAttribute
attributes = GetAttr("C:\foo.txt")
If (attributes And vbReadOnly) Then
attributes = attributes - vbReadOnly
SetAttr "C:\foo.txt", attributes
End If
使用FileSystemObject(需要項目引用到Microsoft腳本運行時)
Dim fso As New FileSystemObject
Dim fil As File
Set fil = fso.GetFile("C:\foo.txt")
If (fil.attributes And ReadOnly) Then
fil.attributes = fil.attributes - ReadOnly
End If
相關問題
- 1. 在R中你如何爲文件寫一個稀疏矩陣?
- 2. 你如何讓一個文件從Windows中的vim寫入?
- 3. 如何,你已經從一個可執行的VB
- 4. 如何寫入VB中的文件中的某一行
- 5. 你將如何爲這個xml文件編寫一個可序列化的類?
- 6. 你如何寫在clojurescript文件?
- 7. 你可以在另一個文件中使用#define變量嗎?
- 8. VB - 如何讀寫二進制文件?
- 9. 如何使一個文件從VB中的一個文本框命名
- 10. 你可以在html文件中寫入xml文件
- 11. 如何寫在一個文本文件
- 12. 玩:你如何寫一個文件上傳模型的測試?
- 13. Python - 你如何在一個文本文件中寫一個新的行,用於一個while循環的迭代?
- 14. 如何在VB中創建一個列表文件?
- 15. 如何可以在文件多次寫入比單個一個
- 16. 在VB中重寫事件
- 17. 如果一個文件可以播放,你如何問gstreamer?
- 18. 你會如何在VB.NET中寫這個?
- 19. 你會如何在Javascript中寫這個?
- 20. 如何確定哪個程序在VB 2005中使用文件?
- 21. 比較文本文件 - 使用VB編寫Igonring一些文本
- 22. 你如何打開一個hxs文件?
- 23. 如何檢查一個文件夾是否可寫使用Qt
- 24. 如何寫一個文件在Python
- 25. 如何使2個文件指針在C++中順序寫入一個文件?
- 26. VB - 使用StreamWriter寫入文件
- 27. 如何在VB中將文本文件從一個文件夾複製到另一個文件夾?
- 28. 如何使用ofstream在另一個目錄中寫入文件?
- 29. 你如何使整個控件在android中可點擊?
- 30. 我如何設計一個使用VB的CSV文件?
在我們的情況下文件有時不可寫入,因爲它們通過我們無法控制的進程複製。所以我們只想涵蓋所有情況。 – Laurent 2009-04-15 08:14:28