How to select folders / files recursively using a label?

If you are having a problem using Vault, post a message here.

Moderator: SourceGear

Post Reply
NTTAKR
Posts: 10
Joined: Wed Oct 26, 2005 6:41 am

How to select folders / files recursively using a label?

Post by NTTAKR » Wed Oct 26, 2005 5:08 pm

Hi!

I wrote a little app to show all labelled versions of a repository to the user.
The user shall have the option to choose a label and get all files to a working folder.

I do not want to iterate over each folder/file so I normally use the following approach to get a list of files:

Code: Select all

            VaultClientFileColl theFiles = new VaultClientFileColl();

			vcfolder = _SGVClient.TreeCache.Repository.Root.FindFolderRecursive(reposItem);
            if (vcfolder != null)
            {
                ParentPath = vcfolder.FullPath;

                theFiles.AddRange(vcfolder.Files);
                if (Recursive)
                {
                    foreach (VaultClientFolder subfolder1 in vcfolder.Folders)
                        subfolder1.GetFilesRecursive(ref theFiles, _SGVClient.TreeCache.Cloaks);
                }

            }
            else
            {
                vcfile = _SGVClient.TreeCache.Repository.Root.FindFileRecursive(reposItem);
                if (vcfile != null)
                {
                    ParentPath = vcfile.FullPath;
                    theFiles.Add(vcfile);
                }
                else
                {
                    throw new Exception(string.Format("{0} does not exist.", reposItem));
                }
            }

            VaultClientFile[] files = (VaultClientFile[])theFiles.ToArray(typeof(VaultClientFile));

             _SGVClient.GetToNonWorkingFolder(files, false, true, MakeWritableType.MakeAllFilesReadOnly, SetFileTimeType.CheckIn, ParentPath, TargetDir, null);

I looked at the sample console application to see how you managed to get a labelled set of files, but I did not understand the usage of the _ci.GetByLabel_GetStructure function.

I am missing anything about folders and files in the code after the GetByLabel_GetStructure function.

Could you please shed some light on the Label_Getstructure usage?

Thanks,

Andreas Kroll

jclausius
Posts: 3706
Joined: Tue Dec 16, 2003 1:17 pm
Location: SourceGear
Contact:

Post by jclausius » Thu Oct 27, 2005 2:03 pm

Andreas:

The first thing you need is a "description" of the contents of a label. This is done with GetByLabel_GetStructure().

The declaration of the method is the following:
bool GetByLabel_GetStructure(
string currentPathToLabelItem,
string labelName,
ref long labelID,
string labelSubItemPath,
out string[] discoveredSubItemPaths,
out VaultClientTreeObject labelStructure,
out long rootID)
  • currentPathToLabelItem = item's repository path $/dir1/dir2/dir3 or $/dir1/dir2/file1. Note, the label does not directly have to be applied to one of these objects, it is just the case that the object is found in the labelName/labelID parameter.

    For example, $/dir may be labeled, but you may want to only get $/dir1/dir2/dir3 as it is exists in the label.
  • labelName = the label you wish to retrieve.
  • labelID = the internal label ID. Note, this is a REF variable, as if you do know the ID, it can be used instead of the string.
  • labelSubItemPath = the Sub Path to any item in the label. This is mostly used if an item is shared within the label. For example, if you labeled $/src, but wish to retrieve src/A/B/C/file (which is also shared in src/X/Y/file) from one of the labels, "src/A/B/C/file" is the label's sub item path.

    If the object is not shared within the label, this param may be null.
  • discoveredSubItemPaths = if labelSubItemPath == null, then the call to GetByLabel_GetStructure fails, but this param is an array of strings of the multiple paths to the item you are requesting.
  • labelStructure - the structure of what the label looks like.
  • rootID - the label's root object id.


Once you have the definition of the labelStructure, you can use it to call GetByLabelToNonWorkingFolder_GetData() to retrieve the actual files.
Jeff Clausius
SourceGear

Post Reply