×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Do we have a VBS version of listing files in a folder?

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

RE: Do we have a VBS version of listing files in a folder?

I just happened to login and see this. I don't login like I used to.

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?

Pretty much depends on what you actually want to do with the file list. Simply display it? Put it in a spreadsheet? Create a simple textfile? Do a mass rename? In other words, iis there more to your code than simply reading a filelist?


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close