且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用于识别子文件夹的脚本

更新时间:2023-12-05 18:38:04

你好,


我认为对于一个如此简单的任务你不需要像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.Application")
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.FileSystemObject")
Set objFolder = objFSO.GetFolder(objStartFolder)
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(objStartFolder)
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
objExcel.Cells(intRow, 1).Value = Subfolder.Path
Set objFolder = objFSO.GetFolder(Subfolder.Path)
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").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit
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 :eof

If 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.