- Option Explicit
-
- ClearReadOnlyAttr "C:\Test"
-
-
-
- Sub ClearReadOnlyAttr(sPath)
- Dim oFso, oFolder, oSubFolders, oFiles, oFile, oSubFolder
-
- Const FILE_READONLY = 1, DIR_READONLY = 16
- Set oFso = CreateObject("Scripting.FileSystemObject")
- Set oFolder = oFso.GetFolder(sPath)
- Set oSubFolders = oFolder.SubFolders
- Set oFiles = oFolder.Files
-
- If oFolder.Attributes And DIR_READONLY Then
- oFolder.Attributes = oFolder.Attributes - DIR_READONLY
- End If
-
- For Each oFile In oFiles
- If oFile.Attributes And FILE_READONLY Then
- oFile.Attributes = oFile.Attributes - FILE_READONLY
- End If
- Next
-
- For Each oSubFolder In oSubFolders
- ClearReadOnlyAttr oSubFolder.Path '递归
- Next
-
- Set oSubFolder = Nothing
- Set oFile = Nothing
- Set oFiles = Nothing
- Set oSubFolders = Nothing
- Set oFolder = Nothing
- Set oFso = Nothing
- End Sub
复制代码
[ 本帖最后由 rat 于 2008-10-20 21:10 编辑 ] |