VB脚本删除特定的子文件夹 [英] VB Script to Delete specific subfolder

查看:86
本文介绍了VB脚本删除特定的子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要VBScript /命令提示符来删除具有特定名称的子文件夹

I am in need of VBScript / command-prompt to delete subfolder which will have specific name

例如:


  1. E:\test\43\5512686\5512698\html\abc

  2. E:\test\ 43\5467686\5512699\html\abc

  3. E:\test\43\5587686\55147589\html\abc

  4. E:\test\45\5517586\5512698\html\abc

  1. E:\test\43\5512686\5512698\html\abc
  2. E:\test\43\5467686\5512699\html\abc
  3. E:\test\43\5587686\55147589\html\abc
  4. E:\test\45\5517586\5512698\html\abc

等。 ,

其中上面的示例 abc文件夹需要删除

wherein above example "abc" folder needs to delete

任何人都可以提供帮助

预先感谢

推荐答案

有关背景/上下文,请参见用于递归文件访问的此框架。给定以下文件夹结构:

For background/context see this skeleton for recursive file access. Given this folder structure:

tree /A ..\test
Folder PATH listing for volume eh
Volume serial number is 0ED6-233C
E:\TRIALS\SOTRIALS\ANSWERS\13415663\TEST
+---vbs
\---df
    +---1
    |   +---b
    |   |   \---x
    |   \---a
    |       \---abc
    \---2
        \---abc
            \---xx

和此概念证明代码:

Option Explicit

Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")

WScript.Quit Main()

Function Main()
  Dim sDir : sDir = "..\test"
  Dim oWorker : Set oWorker = New cWorker
  Main = traverseDir(goFS.GetFolder(sDir), oWorker)
End Function

Class cWorker
  Public Sub processFile(oFile)
    ' not needed
  End Sub
  Public Function processFolder(oFolder)
    WScript.Echo "looking at", oFolder.Path
    processFolder = True
    If "abc" = oFolder.Name Then
       WScript.Echo "will delete", oFolder.Path
       oFolder.Delete
       processFolder = False
    End If
  End Function
End Class

Function traverseDir(oDir, oWorker)
  traverseDir = 0
  Dim oF
  For Each oF In oDir.Files
      oWorker.processFile oF
  Next
  For Each oF In oDir.SubFolders
      If oWorker.processFolder(oF) Then
         traverseDir = traverseDir(oF, oWorker)
      End If
  Next
End Function

输出:

cscript step02.vbs
looking at E:\trials\SoTrials\answers\13415663\test\vbs
looking at E:\trials\SoTrials\answers\13415663\test\df
looking at E:\trials\SoTrials\answers\13415663\test\df\1
looking at E:\trials\SoTrials\answers\13415663\test\df\1\b
looking at E:\trials\SoTrials\answers\13415663\test\df\1\b\x
looking at E:\trials\SoTrials\answers\13415663\test\df\1\a
looking at E:\trials\SoTrials\answers\13415663\test\df\1\a\abc
will delete E:\trials\SoTrials\answers\13415663\test\df\1\a\abc
looking at E:\trials\SoTrials\answers\13415663\test\df\2
looking at E:\trials\SoTrials\answers\13415663\test\df\2\abc
will delete E:\trials\SoTrials\answers\13415663\test\df\2\abc

证据:

tree /A ..\test
Folder PATH listing for volume eh
Volume serial number is 0ED6-233C
E:\TRIALS\SOTRIALS\ANSWERS\13415663\TEST
+---vbs
\---df
    +---1
    |   +---b
    |   |   \---x
    |   \---a
    \---2

您应该能够编写解决您特定问题的脚本。

you should be able to write a script that solves your specific problem.

更新:

看< a href = https://stackoverflow.com/a/13453705/603855>此处以查看应用于移动文件夹的方法。

Look here to see the approach applied to moving folders.

这篇关于VB脚本删除特定的子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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