Vbscript 从子文件夹中查找最后一个名为month的文件夹
我在文件夹树中有按月份分组的报告 “somepath\YYYY\MMMYYYY” 例如Vbscript 从子文件夹中查找最后一个名为month的文件夹,vbscript,automated-tests,qtp,Vbscript,Automated Tests,Qtp,我在文件夹树中有按月份分组的报告 “somepath\YYYY\MMMYYYY” 例如“somepath\2017\MAR2017”。 显然,年文件夹中最多可能有12个文件夹“MMMYYYY”。 系统从以月份名称标识的最后一个文件夹上载文件。即,在2017年1月、2017年2月、2017年3月的文件夹中,应上传2017年3月的文件 我尝试将foldername转换为数字: Dim fso : Set fso = CreateObject("Scripting.FileSystemObj
“somepath\2017\MAR2017”
。
显然,年文件夹中最多可能有12个文件夹“MMMYYYY”
。
系统从以月份名称标识的最后一个文件夹上载文件。即,在2017年1月、2017年2月、2017年3月的文件夹中,应上传2017年3月的文件
我尝试将foldername转换为数字:
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim ObjFolder : Set ObjFolder = fso.GetFolder("somepath\2017\")
Set fc = ObjFolder.SubFolders 'here I should get all folders with months in their names
For each f in fc
a = Month("01-"&left(f.name, 3)&"-"&right(f.name, 4))
print a
Next
它接下来打印:
四,
二,
三,
下一步应该是从这些文件夹中确定最大的数目,并将工作文件夹名称设置为
a = MonthName(maxnumber)&"2017"
workingfolder = "somepath\2017\"&a&"\"
如何识别最大数量或最大月份?以下操作有效:
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim ObjFolder : Set ObjFolder = fso.GetFolder("somepath\2017\")
Set fc = ObjFolder.SubFolders
For i=0 to fc.count
For each f in fc
a = Month("01-"&left(f.name, 3)&"-"&right(f.name, 4))
Redim Preserve arr(fc.count)
arr(i)=a
Next
Next
arrLen = UBound(arr) 'Find the length of array
For j= 0 to arrLen
If arr(j) > max Then
max=arr(j)
End If
Next
Dim OrgFolder : Set OrgFolder = fso.GetFolder(ObjFolder&"\"&MonthName(arr(0), True)&"2017\")