【问题标题】:How to find count of files inside a folder in svn如何在svn中查找文件夹内的文件数
【发布时间】:2014-08-20 11:03:37
【问题描述】:

我想查找 svn 中的文件数。我知道如何检查它是文件还是目录。

       try {
            nodeKind = repository.checkPath("", -1);
        } catch (SVNException ex) {
            Logger.getLogger(Reassignscreen.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (nodeKind == SVNNodeKind.NONE) {
            System.err.println("There is no entry at '" + url + "'.");
            commitClient.doMkDir(new SVNURL[]{SVNURL.parseURIDecoded(url)}, "New Folder");
        }

像这样有什么方法可以检索 svn 中的文件数。

【问题讨论】:

  • 您可以在终端中使用命令。 svn log -v --xml file:///path/to/rep | grep kind=\"file\"|wc -l。来自 - here
  • 我们可以在svn机器上使用这个命令还是我们可以在任何机器上运行它
  • 我认为你只能在svn机器上运行,因为运行它的方式是 \bin\TortoiseProc.exe /command: ,所以你必须指定那里的路径
  • 对@Dhinakar 有帮助吗?
  • 阅读this问题,有一些答案会对你有所帮助。

标签: java svn rabbitvcs


【解决方案1】:

使用此代码会对您有所帮助,

public class DisplayRepositoryList{

static int xmlfilecount = 0;
static ArrayList<String> imagefoldercheck = new ArrayList<String>();

public static void displayrepositorytree(String url, String name, String password) {
    xmlfilecount =0;
    SVNSetupLibrary.setupLibrary();
    SVNRepository repository = null;
    try {
        repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
    } catch (SVNException svne) {
        System.err.println("error while creating an SVNRepository for location '" + url + "': " + svne.getMessage());
     //   System.exit(1);
    }

    ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(name, password);
    repository.setAuthenticationManager(authManager);

    try {
        SVNNodeKind nodeKind = repository.checkPath("", -1);
        if (nodeKind == SVNNodeKind.NONE) {
            System.err.println("There is no entry at '" + url + "'.");
          //  System.exit(1);
        } else if (nodeKind == SVNNodeKind.FILE) {
            System.err.println("The entry at '" + url + "' is a file while a directory was expected.");
         //   System.exit(1);
        }
        System.out.println("Repository Root: " + repository.getRepositoryRoot(true));
        System.out.println("Repository UUID: " + repository.getRepositoryUUID(true));
        System.out.println("");
        imagefoldercheck = new ArrayList<String>();
        listEntries(repository, "");
    } catch (SVNException svne) {
        System.err.println("error while listing entries: "
                + svne.getMessage());
    }
    /*
     * Gets the latest revision number of the repository
     */
    long latestRevision = -1;
    try {
        latestRevision = repository.getLatestRevision();
    } catch (SVNException svne) {
        System.err.println("error while fetching the latest repository revision: "
                + svne.getMessage());
      //  System.exit(1);
    }
    System.out.println("");
    System.out.println("---------------------------------------------");
    System.out.println("Repository latest revision: " + latestRevision);
    }

/*
 * Initializes the library to work with a repository via
 * different protocols.
 */
public static void listEntries(SVNRepository repository, String path)
        throws SVNException {
    Collection entries = repository.getDir(path, -1, null,
            (Collection) null);
    Iterator iterator = entries.iterator();
    while (iterator.hasNext()) {
        SVNDirEntry entry = (SVNDirEntry) iterator.next();

        if (entry.getName().endsWith(".xml")) {
            System.out.println(entry.getName() + "   " + xmlfilecount);
            xmlfilecount = xmlfilecount + 1;
            imagefoldercheck.add(entry.getName());
        }

        System.out.println("imagefoldercheck --> "+imagefoldercheck);
       /*
         * Checking up if the entry is a directory.
         */
        if (entry.getKind() == SVNNodeKind.DIR) {
            listEntries(repository, (path.equals("")) ? entry.getName()
                    : path + "/" + entry.getName());
        }
    }
}

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-22
    • 2013-11-14
    • 1970-01-01
    • 2021-11-28
    • 1970-01-01
    相关资源
    最近更新 更多