找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 13265|回复: 3

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

[复制链接]
发表于 2008-9-27 11:20:13 | 显示全部楼层 |阅读模式
如题,我知道批处理很简单,一个attrib -r 指定目录 /s /d就全解决了,但是VBS好像比较麻烦,不知道该如何实现!

望大虾指教!
多谢了!

[ 本帖最后由 lon91ong 于 2008-9-27 19:17 编辑 ]
发表于 2008-9-27 11:50:21 | 显示全部楼层
直接用FSO的方法很麻烦,要对集合进行遍历循环,而且去只读属性时文件-1,文件夹-16
不如调用attrib命令
CreateObject("WScript.Shell").Run "cmd /c attrib -r 指定目录 /s /d",0
 楼主| 发表于 2008-9-27 11:51:43 | 显示全部楼层
呵呵,看来还是批处理方便啊!
发表于 2008-10-20 21:04:28 | 显示全部楼层
  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 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 01:14 , Processed in 0.017018 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表