Jump to content

Recursivly start cmds in subfolders ?


Recommended Posts

Hi guys,

if anyone has an idea, please let me know ! :-)

I would like to start a cmd that recursively searches through subfolders and starts each cmd called install.cmd it finds in those subfolders.

I do have this code to start the cmd inside the current folder but how do I make it go through each subfolder inside this folder and start all files called "install.cmd" instead ?

set p=%~dp0
for %%i in ("%p%install.cmd") do start "" /wait %%i

Any ideas ? Thanks a lot !

Alex

Link to comment
Share on other sites


You could try something along these lines:

@for /f "delims=" %%i in ('dir/b/s/a-d install.cmd') do @call "%%~i"

Incidentally in the example you gave, because you can only have one file named install.cmd in a single directory, this would have done:

@call install.cmd

Link to comment
Share on other sites

Hi Yzöwl,

unfortunately it does not work just yet the way it is now. The script now starts itself over and over and never comes around to starting any of the scripts in the subfolders. Thats probably because the script that contains your code is also called install.cmd and it calls itself over and over ... any easy way around that except renaming that script in the top dir ?

Also, I had troubles with your call command. It did not really work. As soon as I changed it to this:

@for /f "delims=" %%i in ('dir/b/s/a-d install.cmd') do start "" /wait "%%~i"

... it worked.

Anyway, I have this working now. If you want to spend some time on the first issue above, I would be very thankful. If not, don´t bother :hello:

Bye,

Alex

Link to comment
Share on other sites

If you want to try a VBS script to go threw the sub folders and only run the install.cmd in the sub folders

Save As Install.vbs

Option Explicit
Dim Act :Set Act = CreateObject("WScript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Col, Obj, Str
'-> "." Current Directory The Script Is In
Set Str = Fso.GetFolder(".")
For Each Obj In Str.SubFolders
For Each Col In Obj.Files
'-> Filter Out The Name
If InStr(UCase(Col.Name),UCase("install.cmd")) Then
'-> Make Sure It install.cmd and not SomeAppInstall.cmd Or AppInstall.cmd
If Len(Col.Name) = 11 Then
Act.Run(Chr(34) & Col.Path & Chr(34)),1,True
End If
End If
Next
Next

Edited by gunsmokingman
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...