Do we have a VBS version of listing files in a folder?
Do we have a VBS version of listing files in a folder?
(OP)
Hi,
There is a function 'filelist' on the web in Excel macro but I am looking for a similar func with VBS, which can be run in Window Explorer.
Thanks in advance.
Here is the Excel macro/function 'FILELIST'.
Function FileList(fldr As String, Optional fltr As String = "*.*") As Variant
Dim sTemp As String, sHldr As String
If Right$(fldr, 1) <> "\" Then fldr = fldr & "\"
sTemp = Dir(fldr & fltr)
If sTemp = "" Then
FileList = Split("No files found", "|")
Exit Function
End If
Do
sHldr = Dir
If sHldr = "" Then Exit Do
sTemp = sTemp & "|" & sHldr
Loop
FileList = Split(sTemp, "|")
End Function
There is a function 'filelist' on the web in Excel macro but I am looking for a similar func with VBS, which can be run in Window Explorer.
Thanks in advance.
Here is the Excel macro/function 'FILELIST'.
Function FileList(fldr As String, Optional fltr As String = "*.*") As Variant
Dim sTemp As String, sHldr As String
If Right$(fldr, 1) <> "\" Then fldr = fldr & "\"
sTemp = Dir(fldr & fltr)
If sTemp = "" Then
FileList = Split("No files found", "|")
Exit Function
End If
Do
sHldr = Dir
If sHldr = "" Then Exit Do
sTemp = sTemp & "|" & sHldr
Loop
FileList = Split(sTemp, "|")
End Function
RE: Do we have a VBS version of listing files in a folder?
Anyhow, here are a few ideas to chase after, if you're still curious:
* FileSystemObject - gives lots of things you can do. If nothing else, you can build a loop (with or without subfolder recursion) to loop through all files. I've done this many times to get whatever info I'm after. If it's super large, then be warned this method may take a while.
* SHELL() Command can run many command line commands from Windows. Basically you call SHELL() and you stick your command inside the parentheses, and in quotes inside the parentheses, b/c it expects a string. I've used this for a few things, but at the moment, the exacts are slipping my mind. That said, I would think something like SHELL("DIR >C:\MyTempFolder\MyFancyFileName.txt") would work, but you'd probably need to attach the "CD C:\MyBigFileFolder\" to the front of it, along with a carriage return. Haven't tried, but that's what I would expect. Or create a batch file, and use SHELL() to run the batch file.
Anyhow, those are a couple of ideas.
There is the [a href="https://learn.microsoft.com/en-us/office/vba/langu..."]Dir()[/href] VB/VBA command to test if a directory is real. So there may be something similar in VB/VBA that will list files in a directory to whatever. I imagine you'd want to send it to a spreadsheet, so depending upon how that worked, not sure if you can send it to clipboard and then paste in excel or else send to an array formula that you then loop back out to Excel.
You know, the more I think about this, the more I think, just go use FileSystemObject and create a loop to grab what you want for every file/sufolder. Loads of examples online.
"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
RE: Do we have a VBS version of listing files in a folder?