cancel
Showing results for 
Search instead for 
Did you mean: 

How to count files in a folder and subfolders of the folder.

Former Member
0 Kudos

Hello everyone,

I'm having a difficulty with countin files in a Regular folder and subfolders of the folder. I've tried to use SI_ANCESTOR in a query; however, it gives me innacurate results.

I used this hierarchy to create the code below, and it works to count all the files:

Folder A ---> Folder B( subFolder of A) -


> Folder C(subFolder of B)

//get folder A

IInfoObjects regFolders = infoStore.query ("SELECT * FROM CI_INFOOBJECTS WHERE SI_KIND='Folder' AND SI_PARENTID=0 AND SI_NAME!='User Folders' Order by SI_NAME");

IFolder regFolder = (IFolder) regFolders.get(0);

//get files from Folder A

IInfoObjects rFiles = infoStore.query ("SELECT * FROM CI_INFOOBJECTS WHERE SI_PROGID ! = 'CrystalEnterprise.Folder' AND SI_PARENTID=" + regFolder.getID() );

ilesCount += rFiles.size();

int subCntr=0;

nt subCntr2=0;

//get folder B

IInfoObjects rSubFolders = infoStore.query ("SELECT * FROM CI_INFOOBJECTS WHERE SI_PROGID = 'CrystalEnterprise.Folder' AND SI_PARENTID=" + regFolder.getID() );

//get files from subFolders of Folder A

while (subCntr < rSubFolders.size())

{

IInfoObject subFolder=(IInfoObject)rSubFolders.get(subCntr);

IInfoObjects subFiles = infoStore.query ("SELECT * FROM CI_INFOOBJECTS "

+ " WHERE SI_PROGID != 'CrystalEnterprise.Folder'" AND SI_PARENTID=" + subFolder.getID() );

filesCount += subFiles.size();

//get subFolders of Folder B

IInfoObjects rSubFolders2 = infoStore.query ("SELECT * FROM CI_INFOOBJECTS WHERE SI_PROGID = 'CrystalEnterprise.Folder' AND SI_PARENTID=" + subFolder.getID() );

//get files from subFolders of Folder B

while (subCntr2 < rSubFolders2.size())

{

IInfoObject subFolder2=(IInfoObject)rSubFolders2.get(subCntr2);

IInfoObjects subFiles2 = infoStore.query ("SELECT * FROM CI_INFOOBJECTS "

+ " WHERE SI_PROGID != 'CrystalEnterprise.Folder' AND SI_PARENTID=" + subFolder2.getID() );

filesCount += subFiles2.size();

subCntr2++;

}

subCntr++;

}

As you can see, the code is too complicated, and what if folder C has subFolder?

I'm guessin maybe recursion would be one way to got, but I'm not really good with it, so I was wondering if anyone has any idea on how to go about doing it.

Thank you,

Accepted Solutions (1)

Accepted Solutions (1)

aasavaribhave
Advisor
Advisor
0 Kudos

Hi,

I am not sure if you need such a complicated code. You need to use recursion as shown in code sample below. It begins at top level folders just like in yoru code and then digs in through each of the subfolders in top folders using recursion.

<%@ page import="com.crystaldecisions.sdk.framework.*,

com.crystaldecisions.sdk.occa.infostore.*,

com.crystaldecisions.sdk.plugin.desktop.report.*,

com.crystaldecisions.sdk.plugin.desktop.common.*,

com.crystaldecisions.sdk.exception.SDKException"%>

<%

String username = "administrator";

String password = "password";

String cmsname = "cms name";

String authtype = "secEnterprise";

IEnterpriseSession oEnterpriseSession = null;

try

{

oEnterpriseSession = CrystalEnterprise.getSessionMgr().logon(username, password, cmsname, authtype);

IInfoStore oInfoStore = (IInfoStore)oEnterpriseSession.getService("","InfoStore");

String query = "select * from ci_infoobjects where si_kind='folder' and si_parentid=0 and si_name != 'User Folders'";

IInfoObjects topFolders = oInfoStore.query(query);

if(topFolders.size() < 1)

out.println("no top level folders");

else

{

for(int i=0; i<topFolders.size(); i++)

{

IInfoObject topFolder = (IInfoObject) topFolders.get(i);

int num = GetSubFolders(oInfoStore, topFolder.getID());

}

}

}

catch(SDKException e)

{

out.println(e.toString());

}

finally

{

if ( oEnterpriseSession != null)

oEnterpriseSession.logoff();

}

%>

<%! int GetSubFolders(IInfoStore oInfoStore, int folderID) throws SDKException

{

String query = "select * from ci_infoobjects where si_kind='folder' and si_parentid=" + folderID;

IInfoObjects folders = oInfoStore.query(query);

if(folders.size() < 1)

return 0;

else

{

for(int i=0; i<folders.size(); i++)

{

int numOfSF = GetSubFolders(oInfoStore, ((IInfoObject)folders.get(i)).getID());

}

return folders.size();

}

}

%>

Former Member
0 Kudos

wow,your code works perfectly, and it's short and sweet. Thank you!!!!

Former Member
0 Kudos

hi,

can you please let me know how to run the above JSP file in BO Environment?

Thanks

Former Member
0 Kudos

Hi,

For detailed information, please refer to the BI 4.0 developers guide here.

You can find the section "Setting up the development environment" in developers guide that have every single instruction to execute a java code specific to BI 4.0 environment.

Also, here are the instructions for BO 3.1 environment:

To configure a WAR file for a J2EE application that uses the BusinessObjects Enterprise XI 3.0 and 3.1 Java SDK, complete these steps:

  1. Create a lib folder in the WAR file's WEB-INF folder.
  2. Copy the Enterprise XI 3.0 or 3.1 Java SDK JAR files from the appropriate location below to the WAR file's WEB-INF\lib folder:
    Windows:
    ...\Program Files\Business Objects\common\4.0\java\lib
    UNIX:
    <businessobjects_root>/java/lib
  3. Copy the log4j.jar file from the appropriate location below to the WAR file's WEB-INF\lib folder:
    Windows:
    ...\Program Files\Business Objects\common\4.0\java\lib\external
    UNIX:
    <businessobjects_root>/java/lib/external
  4. Copy the entire crystalreportviewers12 folder from the appropriate location below to the WAR file's root folder.
    Windows:
    ...\Program Files\Business Objects\common\4.0
    UNIX:
    <businessobjects_root>/enterprise12/JavaSDK
  5. Open the web.xml file located in the WAR file's WEB-INF folder.
  6. Specify the location of the utility files used by the report viewers contained in the crystalreportviewers12 folder by inserting the following code below the <display-name> and <description> tags but within the <webapp> tag definition:
    <context-param>
    <param-name>crystal_image_uri</param-name>
    <param-value>/BOXIR3/crystalreportviewers12</param-value>
    </context-param>
    <servlet>
    <servlet-name>CrystalReportViewerServlet</servlet-name>
    <servlet-class>com.crystaldecisions.report.web.viewer.CrystalReportViewerServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>CrystalReportViewerServlet</servlet-name>
    <url-pattern>/CrystalReportViewerHandler</url-pattern>
    </servlet-mapping>
  7. Deploy the WAR file to the J2EE application server.

You are now able to run an application using the BusinessObjects Enterprise XI 3.0 and 3.1 Java SDK on a J2EE web application server.

Hope it helps.

Regards,

Anchal

Answers (0)