[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

VBS怎样去掉文件夹包括子目录及文件的只读属性

如题,我知道批处理很简单,一个attrib -r 指定目录 /s /d就全解决了,但是VBS好像比较麻烦,不知道该如何实现!

望大虾指教!
多谢了!

[ 本帖最后由 lon91ong 于 2008-9-27 19:17 编辑 ]

直接用FSO的方法很麻烦,要对集合进行遍历循环,而且去只读属性时文件-1,文件夹-16
不如调用attrib命令
CreateObject("WScript.Shell").Run "cmd /c attrib -r 指定目录 /s /d",0
命令行参考:hh.exe ntcmds.chm::/ntcmds.htm
求助者请拿出诚心,别人才愿意奉献热心!
把查看手册形成条件反射!

TOP

呵呵,看来还是批处理方便啊!

TOP

  1. Option Explicit
  2. ClearReadOnlyAttr "C:\Test"
  3. Sub ClearReadOnlyAttr(sPath)
  4.         Dim oFso, oFolder, oSubFolders, oFiles, oFile, oSubFolder
  5.         Const FILE_READONLY = 1, DIR_READONLY = 16
  6.         Set oFso = CreateObject("Scripting.FileSystemObject")   
  7.         Set oFolder = oFso.GetFolder(sPath)         
  8.         Set oSubFolders = oFolder.SubFolders         
  9.         Set oFiles = oFolder.Files
  10.   
  11.         If oFolder.Attributes And DIR_READONLY Then
  12.                 oFolder.Attributes = oFolder.Attributes - DIR_READONLY
  13.         End If  
  14.                
  15.         For Each oFile In oFiles   
  16.             If oFile.Attributes And FILE_READONLY Then
  17.                         oFile.Attributes = oFile.Attributes - FILE_READONLY
  18.             End If  
  19.         Next  
  20.                
  21.         For Each oSubFolder In oSubFolders
  22.                 ClearReadOnlyAttr oSubFolder.Path        '递归         
  23.         Next  
  24.       
  25.         Set oSubFolder = Nothing
  26.         Set oFile = Nothing
  27.         Set oFiles = Nothing
  28.         Set oSubFolders = Nothing
  29.         Set oFolder = Nothing            
  30.         Set oFso = Nothing
  31. End Sub
复制代码

[ 本帖最后由 rat 于 2008-10-20 21:10 编辑 ]

TOP

返回列表