Vb Script to get the selected(focussed) file names in a windows folder.

5 pts.
Tags:
VB script
I am trying to get the file names of all the files that has been selected in a folder into an array.

Please help



Software/Hardware used:
Windows XP
ASKED: January 11, 2012  7:21 AM
UPDATED: February 28, 2012  12:01 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

http://www.go4expert.com/forums/showthread.php?t=927

gives an example on reading a directory. I added the array part of it and commented
out the write part of it.
I write in vb but I’m not an expert in it so no promises. I prefer perl.
I’m sure somebody else will chime in with another example.
Here’s the code I ended up with, it works on my win7 machine.
cscript listdir.vbs c:\junk
—-
On Error Resume Next
Dim fso, folder, files, NewsFile,sFolder
Dim myarray(50), count, count2
Set fso = CreateObject(“Scripting.FileSystemObject”)
sFolder = Wscript.Arguments.Item(0)
If sFolder = “” Then
Wscript.Echo “No Folder parameter was passed”
Wscript.Quit
End If
‘ Set NewFile = fso.CreateTextFile(sFolder&”\FileList.txt”, True)
Set folder = fso.GetFolder(sFolder)
Set files = folder.Files
count = 0
For each folderIdx In files
‘ NewFile.WriteLine(folderIdx.Name)
myarray(count) = folderIdx.Name
count = count + 1
Next
For count2 = 0 to count -1
Wscript.Echo myarray(count2) ‘ write out the array
Next
‘ NewFile.Close

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following