简体   繁体   English

打开目录中的最新文件夹

[英]Open the most recent folder in a directory

I'm trying to create a script that will open the latest folder in a directory. 我正在尝试创建一个脚本,该脚本将打开目录中的最新文件夹。

The name of the folder will be different each month (01-Jan, 02-Feb etc). 文件夹的名称每个月都会有所不同(1月1日,2月2日等)。 The below seems to find the latest folder, but I get error File not found when I add in Shell "explorer.exe" & "" & strFullFldrPath, vbNormalFocus to open the folder. 下面似乎找到了最新的文件夹,但是当我在Shell“ explorer.exe”&“”&strFullFldrPath,vbNormalFocus,vbNormalFocus中打开文件夹时,我找不到错误文件。

This is what I have so far. 到目前为止,这就是我所拥有的。

Sub GetLatestFolder()

Dim fso As FileSystemObject
Dim fldrRoot As Folder
Dim SubFld As Folder

Dim strFolderName As String
Dim strFullFldrPath As String


Set fso = New FileSystemObject
Set fldrRoot = fso.GetFolder("\\Hbeu.adroot.hsbc\dfsroot\GB002\RRU\DTCC EU Reports\ETD\")

For Each SubFld In fldrRoot.SubFolders
strFolderName = SubFld.Name
strFullFldrPath = fldrRoot & "\" & SubFld.Name

Shell "explorer.exe" & "" & strFullFldrPath, vbNormalFocus
    Exit For
Next SubFld

End Sub

You try to run "explorer.exeC:\\WHATEVER" ie your missing a space between the executable and its argument. 您尝试运行"explorer.exeC:\\WHATEVER"即您在可执行文件及其参数之间缺少空格。
Quotes are a good idea to accommodate paths with spaces. 引号是一个容纳空格的好主意。

Shell "explorer.exe" & " """ & strFullFldrPath & """, vbNormalFocus

What you have does not guarantee the latest folder is always first, you should apply some logic based on the name or load all directories and sort. 您所拥有的并不能保证最新的文件夹始终位于最前面,您应该基于名称应用某些逻辑或加载所有目录并进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM