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?

  • 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

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.

  • 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/www.mysite.com/web.config  
START c:/Websites/www.mysite.co.uk/web.config  
START c:/Websites/www.mysite.au/web.config

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

  • 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 ".co.uk" } |

    #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.


A very simple *nix equivalent hints out to me that we should spend time in learning *nix shell commands and scripting, even if we predominantly work on MS Windows:

find . -name web.config | xargs start notepad++

This work on MS Windows only if you have Unix utilities installed, such as via Cygwin or (my personal favourite) git bash, which is part of Git for Windows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.