views:

58

answers:

2

Assume I have more than 30 or so open within the Visual Studio IDE. Too many to show without scrolling, which makes a manual count laborious.

I can do Window -> Windows to list them in a popup but it doesn't show a count.

Does it show somewhere (like in the status bar) that I'm missing?

Edit: Why would anyone need this? Well, I wanted to make a find/replace across a lot of files. I dragged the files into VS to make the Find Replace on "All Open Documents" and I just wanted a sanity check that VS had open the same number of files I was expecting - and that it hadn't silently excluded any of my files.

+1  A: 

Not a count, but in the document tab row, off to the right, is an upside-down "Eject" symbol that is a shortcut for the document list region of the Windows tab. You can get an approximate count just by eyeballing that. Seriously, if you can't count them all, you probably have too many open at once.

KeithS
+3  A: 

Paste this sub into a new Macro, it should give you what you want.

Public Sub GetFileCount()

    Dim count = 0
    Dim i As Integer

    For i = 1 To DTE.Windows.Count
        If DTE.Windows().Item(i).Kind = "Document" Then
            count = count + 1
        End If

    Next

    MsgBox("File Count = " & count)

End Sub

Edit:

Based on comments I ran the Macro in VS2010 and did not get the incorrect count mentioned. Try the following changes to see what's actually being counted as a "Document" in the DTE.Windows collection:

Public Sub GetFileCount()

        Dim count = 0
        Dim i As Integer
        Dim msg = ""
        For i = 1 To DTE.Windows.Count
            If DTE.Windows().Item(i).Kind = "Document" Then
                count = count + 1
                msg = msg & DTE.Windows().Item(i).Document.Name & vbCrLf
            End If

        Next

        MsgBox("File Count = " & count & vbCrLf & msg)

    End Sub
Chuck
When I try this in VS2010, the count appears to be 5 greater than the number of files I have open. If I have 1 file open, the macro will display 6. Not sure if anything changed between VS2005 and VS2010 that would affect the count.
Jonathan S.
Maybe it includes other tabs and floating windows that aren't actual file documents, like your Start Page, Output, Unit Test Sessions, etc.
KeithS
@Jonathan I added a change to the macro to include the name of the document as well so you can see what's being counted. In VS2010 the count being returned to me is correct with my tests.
Chuck
Thanks. It was listing several files that weren't visible to me. After doing a "Close all files" and reopening a file, the count appears correct.
Jonathan S.