如何修改此Excel文件以:
1.列出目录的路径,而不仅仅是文件?
1.过滤掉系统和隐藏文件?
以下是目前的情况:
Sub MM()
Dim fResults As Variant
fResults = GetFiles("C:\Temp")
Range("A1").Resize(UBound(fResults) + 1, 1).Value = _
WorksheetFunction.Transpose(fResults)
End Sub
// UDF to populate array with files, assign to a Variant variable.
Function GetFiles(parentFolder As String) As Variant
GetFiles = Filter(Split(CreateObject("WScript.Shell").Exec("CMD /C DIR """ & parentFolder & _
IIf(Right(parentFolder, 1) = "\", vbNullString, "\") & "*.*"" /S /B /A:-D").StdOut.ReadAll, vbCrLf), ".")
End Function
2条答案
按热度按时间e4yzc0pl1#
您的Filter ... IIF ...构造也在删除目录。摆脱它.事
最好做你想做的事
fdbelqdn2#
答案是更改dir命令的参数。
用途:
当前指定的-D隐藏目录。dir参数的完整解释可以在这里找到https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/dir