开发者

Can Visual Studio tell me how many files I have open?

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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜