用于识别子文件夹的脚本 [英] script to identify subfolders
问题描述
我发现这个脚本会创建一个excel表,其中包含特定目录中的所有文件夹和文件。
任何人都可以通过建议我如何编辑它以便它只报告来帮助我第1级子文件夹,其子文件夹的名称为5位数字?
我的目的是这样的,价格为
root folders = year ie:1986,2004,2012
在每年的文件夹中都有第1级子文件夹 这是用最后2年数字+项目命名的5位数项目文件夹#ie:86001,04001,12001
我需要在所有第1级子文件夹中搜索5位#s的文件夹假设是一级子文件夹,但在根文件和第一级文件夹被锁定之前错误地移动过去。(大约3000个第一级子文件夹)这是
我想要修改的代码。如果有人有更好的剧本,我会很高兴见到它。
objStartFolder =" M:\"
设置objExcel = CreateObject(" Excel.Applic
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2
objExcel.Cells(1,1).Value =" Folder"
objExcel.Cells(1,2).Value =" File Name"
设置objFSO = CreateObject(" Scripting.Fi
设置objFolder = objFSO.GetFolder(objStartF
设置colFiles = objFolder.Files
For colFiles中的每个objFile
objExcel.Cells(intRow,1).Value = objfolder.Name
objExcel.Cells(intRow,2).Value = objFile.Name
intRow = intRow + 1
下一页
ShowSubfolders objFSO .GetFolder(objStartF
Sub ShowSubFolders(文件夹)
For Folder.SubFolders中的每个子文件夹
objExcel.Cells(intRow ,1).Value = Subfolder.Path
设置objFolder = objFSO.GetFolder(子文件夹
设置colFiles = objFolder.Files
For colFiles中的每个objFile
objExcel.Cells(intRow,2).Value = objFile.Name
intRow = intRow + 1
下一个
ShowSubFolders子文件夹
下一页
结束子
objExcel.Range(" A1:B1")。Se
objExcel.Selection.Interio
objExcel.Selection.Font.Co
objExcel.Selection.Font.Bo
objExcel.Cells.EntireColum
MsgBox" Done"
你好,
我认为对于一个如此简单的任务你不需要像vbscript这样的roboust环境,一个简单的cmd(批处理)文件正在做这个工作。
将以下内容另存为.cmd和r un来自多年的根文件夹:
@ echo offfor / d %% y in(????)do call:year %% ygoto:EOF: yearset y4 =%1set y2 =%y4:〜/%%/ p%(%y4%\%y2%???)执行调用:project %% p \%y2%goto:EOF: projectfor / d %% m in(%1 ???)do echo Moved?:%% mgoto:eof如果要将结果存储在文件中,将输出重定向到.txt文件。
此解决方案缺少一件事,它没有检查目录名是否真的只包含数字,所以它可能会错误地报告某个文件夹。
I found this script that will create an excel sheet with all the folders and files in a specific dir.
Can anyone help me out by advising how I can edit it so that it will only report 1st level subfolders that have a subfolder with a 5 digit name??
My dir is like this
root folders = year ie: 1986, 2004,2012
In each year folder there 1st level subfolders that are 5 digit project folders named with the last 2 year digits+the project # ie: 86001, 04001, 12001
I need to search all 1st level subfolders for folders with the 5 digit #s that are suppose to be a 1st level subfolder but have been moved in the past by mistake before the root and 1st level folders were locked down.(about 3000 1st level subfolders) Here is
the code i am trying to modify. If anyone has a better script I would be very glad to see it
objStartFolder = "M:\"
Set objExcel = CreateObject("Excel.Applic
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2
objExcel.Cells(1, 1).Value = "Folder"
objExcel.Cells(1, 2).Value = "File Name"
Set objFSO = CreateObject("Scripting.Fi
Set objFolder = objFSO.GetFolder(objStartF
Set colFiles = objFolder.Files
For Each objFile in colFiles
objExcel.Cells(intRow, 1).Value = objfolder.Name
objExcel.Cells(intRow, 2).Value = objFile.Name
intRow = intRow + 1
Next
ShowSubfolders objFSO.GetFolder(objStartF
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
objExcel.Cells(intRow, 1).Value = Subfolder.Path
Set objFolder = objFSO.GetFolder(Subfolder
Set colFiles = objFolder.Files
For Each objFile in colFiles
objExcel.Cells(intRow, 2).Value = objFile.Name
intRow = intRow + 1
Next
ShowSubFolders Subfolder
Next
End Sub
objExcel.Range("A1:B1").Se
objExcel.Selection.Interio
objExcel.Selection.Font.Co
objExcel.Selection.Font.Bo
objExcel.Cells.EntireColum
MsgBox "Done"
Hello,
I think for a so simple task as this you won't need a roboust environment like vbscript, a simple cmd (batch) file is doing this job.
Save the following as .cmd, and run from the root folder of the years:
@echo offfor /d %%y in (????) do call :year %%ygoto :EOF:yearset y4=%1set y2=%y4:~-2%for /d %%p in (%y4%\%y2%???) do call :project %%p\%y2%goto :EOF:projectfor /d %%m in (%1???) do echo Moved?:%%mgoto :eofIf you want it to store the result in a file, redirect the output to a .txt file.
One thing is missing from this solution it is not examining if the directory names really contains only numbers, so it can falsly report some folder.
这篇关于用于识别子文件夹的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!