使用VBA遍历所有子文件夹

编程入门 行业动态 更新时间:2024-10-07 18:23:50
本文介绍了使用VBA遍历所有子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在寻找一个VBA脚本,该脚本将循环遍历指定文件夹的所有子文件夹.当我说所有子文件夹时,我的意思是指定文件夹内的每个文件夹,该文件夹内的每个文件夹以及该文件夹内的每个文件夹...从理论上讲,可以有无限嵌套的子文件夹,但实际上,它可能不会超过3或4.我使用的是VBA脚本运行时对象,因此一旦循环进入该文件夹,便可以检查某些文件的属性(但是我知道该怎么做).

I'm looking for a VBA script that will loop through all subfolders of a specified folder. When I say all subfolders, I mean each folder inside the specified folder, and each folder inside of that, and each folder inside of that...in theory there could be infinite nested subfolders, but in actuality it will probably not go above 3 or 4. I'm using the VBA Scripting Runtime objects, so that once I loop into the folder I can check properties of some files (but I know how to do that part).

谢谢您的帮助!

此问题与先前包含已知目录的问题中列出的相似"问题不同,而此处的需要是查找已知和未知目录.还需要多层子目录.你们真的应该在解开重复项"之前先阅读问题.

This question is different from the listed "similar" questions in the previous questions contained known directories, whereas the need here was to find known and unknown directories. Also needed multiple layers of subdirectories. You guys really should just read the question before you fire off "duplicate".

推荐答案

只是简单的文件夹下钻.

Just a simple folder drill down.

sub sample() Dim FileSystem As Object Dim HostFolder As String HostFolder = "C:\" Set FileSystem = CreateObject("Scripting.FileSystemObject") DoFolder FileSystem.GetFolder(HostFolder) end sub Sub DoFolder(Folder) Dim SubFolder For Each SubFolder In Folder.SubFolders DoFolder SubFolder Next Dim File For Each File In Folder.Files ' Operate on each file Next End Sub

更多推荐

使用VBA遍历所有子文件夹

本文发布于:2023-05-28 00:46:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/308223.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:词库加载错误:Could not find file 'D:\淘小白 高铁采集器win10\Configuration\Dict_Sto

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!