Java 如何在svn中查找文件夹中的文件数
我想找到svn中的文件数。我知道如何检查它是文件还是目录Java 如何在svn中查找文件夹中的文件数,java,svn,rabbitvcs,Java,Svn,Rabbitvcs,我想找到svn中的文件数。我知道如何检查它是文件还是目录 try { nodeKind = repository.checkPath("", -1); } catch (SVNException ex) { Logger.getLogger(Reassignscreen.class.getName()).log(Level.SEVERE, null, ex); } if (nodeKin
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中的文件计数。使用此代码,它将帮助您
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());
}
}
}
公共类DisplayRepositoryList{
静态int-xmlfilecount=0;
静态ArrayList imagefoldercheck=新建ArrayList();
公共静态void displayrepositorytree(字符串url、字符串名称、字符串密码){
xmlfilecount=0;
SVNSetupLibrary.setupLibrary();
SVNRepository repository=null;
试一试{
repository=SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
}捕获(svne){
System.err.println(“为位置“+url+”创建SVNRepository时出错:”+svne.getMessage());
//系统出口(1);
}
ISVNAuthenticationManager authManager=SVNWCUtil.createDefaultAuthenticationManager(名称、密码);
setAuthenticationManager(authManager);
试一试{
SVNNodeKind nodeKind=repository.checkPath(“,-1);
if(nodeKind==SVNNodeKind.NONE){
System.err.println(“在“+url+”处没有条目”);
//系统出口(1);
}else if(nodeKind==SVNNodeKind.FILE){
System.err.println(“在“'+url+”处的条目是一个文件,而预期是一个目录。”);
//系统出口(1);
}
System.out.println(“存储库根:“+Repository.getRepositoryRoot(true));
System.out.println(“存储库UUID:+Repository.getRepositoryUUID(true));
System.out.println(“”);
imagefoldercheck=新建ArrayList();
列表项(存储库“”);
}捕获(svne){
System.err.println(“列出条目时出错:”
+svne.getMessage());
}
/*
*获取存储库的最新版本号
*/
长期视力=-1;
试一试{
latestRevision=repository.getLatestRevision();
}捕获(svne){
System.err.println(“获取最新存储库版本时出错:”
+svne.getMessage());
//系统出口(1);
}
System.out.println(“”);
System.out.println(“-------------------------------------------------------------”;
System.out.println(“存储库最新版本:+latestRevision”);
}
/*
*通过初始化库以使用存储库
*不同的协议。
*/
公共静态void列表项(SVNRepository存储库,字符串路径)
抛出SVNException{
集合条目=repository.getDir(路径,-1,null,
(集合)空);
迭代器迭代器=entries.Iterator();
while(iterator.hasNext()){
SVNDirEntry entry=(SVNDirEntry)迭代器.next();
if(entry.getName().endsWith(“.xml”)){
System.out.println(entry.getName()+“”+xmlfilecount);
xmlfilecount=xmlfilecount+1;
add(entry.getName());
}
System.out.println(“imagefoldercheck-->”+imagefoldercheck);
/*
*检查条目是否为目录。
*/
if(entry.getKind()==SVNNodeKind.DIR){
listEntries(存储库,(path.equals(“”)?entry.getName()
:path+“/”+entry.getName());
}
}
}
}您可以在终端中使用命令<代码>svn日志-v--xmlfile:///path/to/rep |grep kind=\“file\”wc-l。From-我们可以在svn机器上使用该命令,还是可以在任何机器上运行该命令?我认为您只能在svn机器上运行,因为运行该命令的方式是\bin\TortoiseProc.exe/command:,所以您必须指定路径,它是否有助于@Dhinakar?阅读问题,这里有一些答案可以帮助您。