简体   繁体   English

如何在SVN中的文件夹中查找文件数

[英]How to find count of files inside a folder in svn

I want to find the count of files inside the svn. 我想查找svn中文件的数量。 i know how to check is it a file or directory. 我知道如何检查它是文件还是目录。

       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");
        }

Like this is there any way to retrieve the count of files inside the svn. 像这样,有任何方法可以检索svn中的文件计数。

Use this code it will help you, 使用此代码将对您有所帮助,

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());
        }
    }
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM