cancel
Showing results for 
Search instead for 
Did you mean: 

Count the Number of files in the folder

Former Member
0 Kudos

Hi,

Is it possible through PI; to count the number of files on perticular server and perticular folder on perticular date, and report it through email?
finding the ways to do it.

Accepted Solutions (1)

Accepted Solutions (1)

rajasekhar_reddy14
Active Contributor
0 Kudos

I would suggest you to handle this requirement using Shell scripts , because very much possible and easy to implement using Scripts/

If you keen on implementing PI then mapping level you have to perform File lookup to find the number of files.

Even you can try using Adapter modules also.

Former Member
0 Kudos

Thanks Raja.

  so can I use this shell scripting in Communication channel of file adapter?
is it poosible for you to send me the script.

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi Prema.

I am Not good in scripting , take help from UNIX Team for them it is 10 mnts job to write to script which can give number if files based on your logic.

Please search in web.

Once your Script ready then you can execute script stand alone or using PI communication channel.

But some client dont prefer this approach this case using java maping or UDF you can achive it but you have to perfrom file look and have to to write logic in UDF/Java mapping.

Regards,

Raj

Former Member
0 Kudos

Raja, how does adapter module help me in this case?

rajasekhar_reddy14
Active Contributor
0 Kudos

Adapter module is last option to consider insted of adapter module try below appraoch

1)Develop dummy interfacem like creare one dummy folder and point sender communictaion channel to connect Dummy folder to run Interface,

2)Mapping level write a Java mapping to connect FTP(File look up very much possible) and count number of files(using JAVA this is very easy) and JAVA Mapping returns number of files .

3)Send JAVA Mpaping out to via email using Mail adapter.

rajasekhar_reddy14
Active Contributor
baskar_gopalakrishnan2
Active Contributor
0 Kudos

Btw, did you get chance to read the links that I provided in my previous reply? Create simple java File class and you can retrieve details about the file system from it. In addition to previous reply, go through this links for further help.

list of files in a specific directory logic

http://www.codebeach.com/2008/03/get-list-of-files-in-directory-using.html

sort files for date

http://www.kodejava.org/examples/371.html

Former Member
0 Kudos

Ok let me explain my scenario:

i have interface  File-->PI-->File.  As soon as this interface completes i need to trigger email with no' of files created on target system.

i see from the below link from Baskar; there is something called " File change notification"

WatchServicewatcher = FileSystems.getDefault().newWatchService();

Path dir = ...

WatchKeykey = dir.register(watcher, ENTRY_CREATE);

for (;;) {

WatchKeykey = watcher.take();

for (WatchEvent<?> event: key.pollEvents()) {

if (event.kind() == ENTRY_CREATE) {

Path name = (Path)event.context();

System.out.format(“%s created%n”, name);

}

}

key.reset();

}

how do i make use of this?

Former Member
0 Kudos

Yes I went through the links you provided Baskar; they are useful.

Answers (1)

Answers (1)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

One possible way is using java mapping and inside the mapping use the following java classes to find out details about files and  in the receiver system use mail adapter to send mail.

use File class to get file system details and then pass the output to the mail receiver system.

Refer below links

http://docs.oracle.com/javase/1.4.2/docs/api/java/io/File.html

http://www.oracle.com/us/technologies/java/file-system-api-428204.pdf