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

返回列表