Enumerating the # and names of files in a VSS folder

A customer asked me this question via email today. Unable to remember how to do this (I've been off VSS for over a year), I pinged one of the VSS team's awesome developers, Alin, who promptly responded with this gem:

"You can use VSS Automation to find out the number of files in a folder and their names. Here is the function for doing that:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim db As New SourceSafeTypeLib.VSSDatabase

        db.Open("\\alinc00\vss$\", "Guest", "")

        Dim item As SourceSafeTypeLib.VSSItem

        item = db.VSSItem("$/")

        MsgBox("Total number of files and subfolders = " + item.Items.Count.ToString)

        Dim files As Integer

        Dim child As SourceSafeTypeLib.VSSItem

        files = 0

        For Each child In item.Items

            If child.Type = SourceSafeTypeLib.VSSItemType.VSSITEM_FILE Then

                files = files + 1

            End If

        Next

        MsgBox("Total number of files = " + files.ToString)

    End Sub

The command line SS.exe alone cannot be used, but combined with other utilities it can provide the answer.

ss dir $/ | findstr /R "^[^\$]" | wc –l

(ss dir lists the files and folders, findstr filters out files, wc counts the lines)

Subtract 1 from the answer to find the number of files (because the last line displayed by ss.exe contains the total number of files and folders)  or use something like

@for /F %I in ('ss dir $/ ^| findstr /R "^[^\$]" ^| wc -l') do set /a FILES=%I-1 > NUL

@echo There are %FILES% files in this folder

Published 13 October 05 12:55 by KorbyP

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Baarish said on October 20, 2005 9:10 AM:
I am trying to calculate the size of folders placed under VSS.
While I am able to calculate the folder sizes recursively for Directories & SubDirectories placed in local drive, if I try to use the same approach to calculate folder sizes in VSS I get the following error:

Exception :An unhandled exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll
Additional information: Could not find a part of the path "\\\Source\Project1\Testing".


Following is the code:

Imports SourceSafeTypeLib
Imports System.IO
Form Load()
Dim db As New SourceSafeTypeLib.VSSDatabase
db.Open("\\Source\Project1", "ani", "abc12$$")

Dim item As SourceSafeTypeLib.VSSItem

item = db.VSSItem("$/Testing")

MsgBox("Total number of files and subfolders = " + item.Items.Count.ToString)



Dim size As Long

Dim d As New DirectoryInfo("\\Source\Project1" & "\" & item.Name)

size = DirSize(d)



End Sub


Public Shared Function DirSize(ByVal d As DirectoryInfo) As Long
Dim Size As Long = 0
' Add file sizes.
Dim fis As FileInfo() = d.GetFiles() 'Throws Exception
Dim fi As FileInfo
For Each fi In fis
Size += fi.Length
Next fi
' Add subdirectory sizes.
Dim dis As DirectoryInfo() = d.GetDirectories()
Dim di As DirectoryInfo
For Each di In dis
Size += DirSize(di) 'To get direstories/files under current directory
Next di
Return Size
End Function 'DirSize





The VSS is on the local machine.Is there any API through which I can get the physical path to VSS database..so that I can access all the working folders under it, and thereby calulate the folder size.

Your help in this regard would be highly appreciated.

Thanking in advance.

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

Search

This Blog

Syndication

Page view tracker