SharpSVN读取所有文件名

时间:2009-06-29 23:09:24

标签: c# svn file sharpsvn

在SharpSVN上仍然有点n00b,我希望得到一些简单的代码来打开SVN存储库,并且(至少)读取特定文件夹中所有文件的完整路径。

让我们说这个文件夹是\ trunk \ source

我不打算结帐或提交,只需阅读列表

我也希望阅读所有文件,而不仅仅是已更改的文件。

2 个答案:

答案 0 :(得分:16)

好吧,好像我找到了一个方法..

        bool gotList;
        List<string> files = new List<string>();

        using (SvnClient client = new SvnClient())
        {
            Collection<SvnListEventArgs> list;

            gotList = client.GetList(projectPath, out list);

            if (gotList)
            {
                foreach (SvnListEventArgs item in list)
                {
                    files.Add(item.Path);
                }
            }
        }

答案 1 :(得分:7)

在记事本中匆匆写了这个;遗憾。

SvnClient client = new SvnClient();
client.Authentication.DefaultCredentials = new NetworkCredential("svnuser", "svnpass");
SvnUriTarget folderTarget = new SvnUriTarget("https://mysvnserver.com/mysvnpath");
List<String> filesFound = getFolderFiles(client, folderTarget);

// GetFolderFiles
//   Function that, given a SvnClient and Target to a folder, returns a list of files
private List<String> getFolderFiles(SvnClient client, SvnTarget folderTarget)
{
    List<String> filesFound = new List<String>();
    List<SvnListEventArgs> listResults;

    if (client.GetList(folderTarget, out listResults))
    {
        foreach (SvnListEventArgs item in listResults)
            if (item.Entry.NodeKind == SvnNodeKind.File)
                filesFound.Add(item.Path);

        return filesFound;
    }
    else
       throw new Exception("Failed to retrieve files via SharpSvn");
}