0

I am trying to run a vbscript in all the subfolders of my current dir. So far I have:

CreateObject("Wscript.Shell").Run("""*\dirlistnew.vbs""")

But that doesn't work. If I remove the *\ it will work in the current dir, but not the subs. I know I'm missing something simple. Been searching and trying things for hours to no avail.

peter
  • 41,770
  • 5
  • 64
  • 108
Greg
  • 107
  • 1
  • 2
  • 14

1 Answers1

0

Got you this from my library of snippets, adjust to you needs. Not tested, I'm more in to Ruby the last couple of years.

'call our sub with the desired path as option
' this needs to be a Folder object, not a String
' FSO.GetFolder will return that object given a path as string
ShowSubfolders FSO.GetFolder(path)

Sub CreateHtml(path)
  ' put here the code from your other script (best)
  ' or do your call to execute the other script
  ' you probably need the path so you pass it as a parameter
End Sub

Sub ShowSubFolders(Folder)
' a Folder has the method SubFolders, 
' gives a collection of subfolders that can be enumerated
' with For Each construct
  For Each Subfolder in Folder.SubFolders
    ' print the subfolder so you can follow the progress
    Wscript.Echo Subfolder.Path
    ' and call the sub that creates the html file
    CreateHtml Subfolder.Path
    ' here the magic of recursion, the sub is calling itself with 
    ' as parameter the subfolder to process the subsubfolders etc
    ShowSubFolders Subfolder
  Next
End Sub

NB in Ruby it's just one line Dir["#{folder}/*"].each{|f| puts f if File.directory?(f) }

user692942
  • 16,398
  • 7
  • 76
  • 175
peter
  • 41,770
  • 5
  • 64
  • 108
  • When you decide to answer questions like this you just encourage more of them. The question is poor at best and shows little or no attempt to approach the problem themselves, not to mention it's also been answered before. – user692942 Jan 22 '17 at 12:26
  • yes but you scare new users away like that, hadn't seen it was a double though – peter Jan 22 '17 at 12:30
  • NB: they are asking for a VBScript solution not Ruby. – user692942 Jan 22 '17 at 12:30
  • If they scare away that easily then this isn't the place for them. I made the same mistakes but instead of running away, I read the tour and checked [ask], I asked on [meta] and adjusted. We shouldn't have to change because some are too sensitive to readjust and realise we are trying to help them. All this does is validate that what they are doing is right, which is the wrong message. – user692942 Jan 22 '17 at 12:33
  • 1
    and I suppose now he gets that.., so let's finish this discussion – peter Jan 22 '17 at 12:41
  • I'm more concerned about you getting it tbh. – user692942 Jan 22 '17 at 13:04
  • I didn't run away I'm in Australia. I went to bed. Now I'm going to work. Oh and we all started somewhere didn't we. I'm trying to understand all of this and just asked for some help, not attitude... Whatever! – Greg Jan 22 '17 at 19:56
  • @greg I didn't say you did, I was referring to being scared off *(refer to peter's [earlier comment](http://stackoverflow.com/questions/41790493/using-a-vbscript-to-run-another-vbscript-in-all-subfolders#comment70770408_41790584))*. But to be honest your attitude is all wrong anyway judging by that response, just expecting help with little or no effort on your part isn't the best away to ask here. I recommend you read [ask] thoroughly first, maybe even look through [meta] to understand the community better. – user692942 Jan 22 '17 at 21:00
  • Ok I'm sorry if I came across all wrong I really didn't mean it. I don't know much at all about VB scripts and I have searched through here and google trying to make sense of it all, but I just can't figure out how it all works. I know I'm missing something probably obvious to you guys who know this stuff very well. – Greg Jan 23 '17 at 06:18
  • I don't do this for a living, I'm just trying to set something up for our family to watch home videos and probably trying to get too tricky with it. I'm just a hobbyist who's admittedly not to bright when it comes to this stuff. I didn't mean to come across with a bad attitude. I really have searched and tried quite a few different ways, but I just can't find a way to do what I want to do. Maybe I'm asking at the wrong website. Sorry. – Greg Jan 23 '17 at 06:18
  • @greg in which case I doubt peters answer without explanation is going to help you much. You should try providing more information, one line of code and saying it doesn't work tells us nothing about what you are trying to accomplish with next to no VBScript experience. – user692942 Jan 23 '17 at 07:13
  • @peter relevant - [Is answering a dupe acceptable as to not “scare away” new users?](http://meta.stackoverflow.com/a/284361/692942) – user692942 Jan 23 '17 at 07:15
  • I understand that this is a dupe now, just learned what that means... look at me go! I have a vbs file in each subdir of the current dir that will read the dir it is in and create an html file with links to each file in each dir. The problem is I need to run the vbs in each sub dir to create the html file. I am trying to automate this instead of manually going through each dir to execute the vbs. I hope this makes sense. As I have said I am sorry for my ignorance but something is just not clicking with me. – Greg Jan 23 '17 at 07:44
  • @Greg, since you are beginner, I added some comments to help you get what is going on in the code, feel free to ask if you don't understand – peter Jan 23 '17 at 08:00
  • @Lankymart, funny you reference to a dupe yourself, they clearly have their positive sides – peter Jan 23 '17 at 08:02
  • @Greg Ill adapot the answer to reflect that – peter Jan 23 '17 at 08:13
  • @Peter thank you I will take your answer and see what I can do with it. Thank you all for your time. – Greg Jan 23 '17 at 08:35
  • @peter I selected that one purely because of the wording of the question and the answer, the others it's marked as a dup of don't quite fit. – user692942 Jan 23 '17 at 10:02
  • @Greg, you'r welcome, if the answer helps please accept it as an answer otherwise the question remains open, if not you'd better delete the question in order to avoid more comments like these from Lankymart – peter Jan 23 '17 at 10:16
  • @peter You're never going to get it! You completely undermine the work we are trying to do here and what annoys me more is you know what you're doing but carry on doing it. Undermining me in your comments just shows your lack of respect for the [so] ethos and your real drive behind answering questions. Last I'm going to say, but disappointed is an understatement! – user692942 Jan 23 '17 at 11:42
  • @peter if you want an example of a [recursive function answer](http://stackoverflow.com/a/41192464/692942), I ended up giving this on a duplicate after [being bullied into it](http://stackoverflow.com/questions/41187136/apply-existing-vbs-folder-search-to-sub-folders/41192464#comment69584111_41187947) - bear in mind, it was me who flagged the question as a duplicate in the first place! We get bullied into answering because people have an expectation, which leaving answers like this to duplicate questions breeds. – user692942 Jan 23 '17 at 11:47