VBS删除只读属性recursivelty [英] VBS Remove Readonly attribute recursivelty

查看:170
本文介绍了VBS删除只读属性recursivelty的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的VBS和去除试验只读递归式的目录属性。

它仅除去读取属性的文件,但不为目录。此外,这些目录中的文件似乎失去了其相关的程序链接,现在所有的表示作为一个未注册的文件类型。任何帮助是极大的AP preciated。

更新:我明白为什么这些文件现在已经失去了联系。这是因为。用于分隔扩展名已被删除!卫生署!理想情况下,我想仅重命名文件名。

  re.Pattern =[_]
re.IgnoreCase = TRUE
re.Global = TRUERemoveReadonlyRecursive(T:\\山洪\\)子RemoveReadonlyRecursive(DirPath)
    只读= 1
    设置oFld = FSO.GetFolder(DirPath)    对于oFld.Files每个OFILE
        如果oFile.Attributes和只读,则
            oFile.Attributes = oFile.Attributes XOR只读
        万一
        如果re.Test(oFile.Name)然后
            oFile.Name = re.Replace(oFile.Name,)
        万一
    下一个
    对于oFld.SubFolders每个oSubFld
        如果oSubFld.Attributes和只读,则
            oSubFld.Attributes = oSubFld.Attributes XOR只读
        万一
        如果re.Test(oSubFld.Name)然后
            oSubFld.Name = re.Replace(oSubFld.Name,)
        万一        RemoveReadonlyRecursive(oSubFld.Path)
    下一个结束小组


解决方案

看来要自动运行一个脚本可重复的动作。你为什么不使用 ATTRIB 命令来为你做的:

  ATTRIB -rT:\\山洪\\ *。*/ S

如果你想将它连接到一个可点击的图标,你可以把在一个批处理文件。

编辑:
为了从VBScript默默地运行它:

 设置的WshShell = WScript.CreateObject(WScript.Shell)
WshShell.RunATTRIB -rT:\\山洪\\ *。*,/ S,0,真)

EDIT2:
要更换除最后一个时期的一切,使用常规的前pression这样的:

  =文件名我的file.name.001.2012.extension
设置正则表达式=新的RegExp
做两次捕获:
除了最后一个点1.一切
'2.最后一个点而这一切,是不是一个点后,
regEx.Pattern =(。*)^([^] \\ +)$'做两次捕获:替换一切是在第一次捕捉什么也没有点并追加第二捕获
对于regEx.Ex​​ecute每场比赛(文件名)
    newFileName =取代(match.su​​bmatches(0),,,。)及match.su​​bmatches(1)
下一个

I'm very new to VBS and experimenting with removing the read only attribute from a directory recursively.

It's removing the read only attribute for files but not for the directories. Also The files within these directories seem to have lost their associated program link and are now all showing as an unregistered file type. Any help is greatly appreciated.

Update: I can see why the files have lost their associations now. It's because the . which separates the name from the extension has been removed! Doh! Ideally I'd like to rename the filename only.

re.Pattern =  "[_.]"
re.IgnoreCase = True
re.Global = True

RemoveReadonlyRecursive("T:\Torrents\")

Sub RemoveReadonlyRecursive(DirPath)
    ReadOnly = 1
    Set oFld = FSO.GetFolder(DirPath)

    For Each oFile in oFld.Files
        If oFile.Attributes AND ReadOnly Then
            oFile.Attributes = oFile.Attributes XOR ReadOnly
        End If
        If re.Test(oFile.Name) Then
            oFile.Name = re.Replace(oFile.Name, " ")
        End If
    Next
    For Each oSubFld in oFld.SubFolders
        If oSubFld.Attributes AND ReadOnly Then
            oSubFld.Attributes = oSubFld.Attributes XOR ReadOnly
        End If
        If re.Test(oSubFld.Name) Then
            oSubFld.Name = re.Replace(oSubFld.Name, " ")
        End If

        RemoveReadonlyRecursive(oSubFld.Path)
    Next

End Sub

解决方案

It seems you want to automate a repeatable action by a script. Why don't you use the attrib command to do that for you:

attrib -r "T:\Torrents\*.*" /S

You can place that in a batch file if you want to attach it to an clickable icon.

EDIT: To run it from VBScript silently:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "attrib -r ""T:\Torrents\*.*"" /S", 0, true)

EDIT2: To replace everything except the last period, use a regular expression like:

filename = "my file.name.001.2012.extension"
Set regEx = New RegExp
' Make two captures:
' 1. Everything except the last dot
' 2. The last dot and after that everything that is not a dot
regEx.Pattern = "^(.*)(\.[^.]+)$"     ' Make two captures:

' Replace everything that is a dot in the first capture with nothing and append the second capture        
For each match in regEx.Execute(filename)
    newFileName = replace(match.submatches(0), ".", "") & match.submatches(1)
Next

这篇关于VBS删除只读属性recursivelty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆