标题: VBS怎样去掉文件夹包括子目录及文件的只读属性 [打印本页]
作者: lon91ong 时间: 2008-9-27 11:20 标题: VBS怎样去掉文件夹包括子目录及文件的只读属性
如题,我知道批处理很简单,一个attrib -r 指定目录 /s /d就全解决了,但是VBS好像比较麻烦,不知道该如何实现!
望大虾指教!
多谢了!
[ 本帖最后由 lon91ong 于 2008-9-27 19:17 编辑 ]
作者: zqz0012005 时间: 2008-9-27 11:50
直接用FSO的方法很麻烦,要对集合进行遍历循环,而且去只读属性时文件-1,文件夹-16
不如调用attrib命令
CreateObject("WScript.Shell").Run "cmd /c attrib -r 指定目录 /s /d",0
作者: lon91ong 时间: 2008-9-27 11:51
呵呵,看来还是批处理方便啊!
作者: rat 时间: 2008-10-20 21:04
- 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 编辑 ]
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |