Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm on a windows (server 2008) computer that serves websites. The sites are organised into folders:


Each of these folders shares almost identical content, apart from config files like web.config.

I want to open the same file within all these websites to perform some editing.

Is there a Dos / Powershell command I can write to open all files that share the same directory structure, file name and extension, for example opening the config files that are within a specific directories off of the root websites folder?

Can I open them into a specific text editor?

share|improve this question
Your question is confusing. In the title you want to open all files based upon directory structure, yet your question reads as if it's only 1 type of file and you know where they are (so no need to open by structure) – Dave Jul 31 '13 at 8:48
Okay - I've clarified the question – digiguru Jul 31 '13 at 8:56
up vote 1 down vote accepted

Use this powershell script:

$editorPath = "C:\Program Files (x86)\Notepad++\notepad++.exe"
$websites = Get-ChildItem -Path "C:/Websites" | Where { $_.PSIsContainer }
foreach ($website in $websites)
    $webConfigPath = $website.FullName + "\web.config"
    if (Test-Path -Path $webConfigPath)
        Start-Process -FilePath $editorPath -ArgumentList $webConfigPath

It will open all web.config files in all the folders of C:/Websites with notepad++.

You could also use AppCmd.exe to get the websites. This will only get websites instead of all folders.

share|improve this answer
Hi digiguru, did this answer work for you? – Rubanov Aug 5 '13 at 12:58
I would just point out that your answer was a great springboard, but I think it was slower because it loops through directories and then tries to match a file inside. My answer only loops through the web.config files and seems to perform faster. – digiguru Sep 3 '13 at 10:54

This answer was based upon the original question (Since question is updated, this answer is not 100% relevant but, it may still be useful in future so I won't delete it)

You can use the start command in a batch file. Since I assume you already know where the config files are, you'll be able to write a list and then execute it from a batch file.

START c:/Websites/  
START c:/Websites/  
START c:/Websites/

You may need to associate the config file to open with a specific editor as this will open the file with the associated program.

share|improve this answer
Assuming that there may be more websites in the future, I don't want to change this BAT file every time there is a new site. – digiguru Jul 31 '13 at 8:48

Here is the script I have used in it's entireity

#First choose an editor
$editorPath = "C:\Program Files (x86)\Notepad++\notepad++.exe"

#Next loop through a folder recusivly looking for "web.config"
#Recursive allows us to get websites stored inside websites
Get-ChildItem -Path "C:/Websites/" -recurse -filter web.config |

    #This is a where clause for each file.
    #I can find just the websites for a specific domain 
    #(or just delete this line below)
    ?{ $_.Directory.Name -match "" } |

    #Now fire open that editor with this specific file
    %{Start-Process -FilePath $editorPath -ArgumentList $_.fullname}

The files fill drop into your editor one by one as they are found.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .