java code--遍历目录和文档

from:http://opencms-forum.de/opencms-forum/viewthread?thread=1211&lastpage=yes

 <c:set var="p_nsjg" >/nsjg/</c:set>
	<%
	CmsJspActionElement action = new CmsJspActionElement(pageContext,request,response);

	CmsObject cms = action.getCmsObject();
	
	try {
		
		
		List listFolders =cms.getSubFolders("/nsjg/");
		CmsFolder cmsfolder= null;
		for(int i=0;i<listFolders.size();i++){
		cmsfolder=(CmsFolder) listFolders.get(i);
		
		%>
		<c:set var="folderName"><%=cmsfolder.getName()%></c:set>
		
		<li><a href="<cms:link>${p_nsjg}<%=cmsfolder.getName()%></cms:link>"><cms:property name="Title" file="${p_nsjg}${folderName}/" /></a></li>
		<%
		}
		
		List listFiles = cms.getFilesInFolder("/");	
		for(int i=0;i<listFiles.size();i++){
			CmsFile cmsfile= (CmsFile) listFiles.get(i);
			out.println(cmsfile.getName()+ i);
		}
	} catch (CmsException e) {
		out.println(e);
	}
	%>

你可能感兴趣的:(java)