execute BSFN for each file in directory

nkuebelbeck

nkuebelbeck

VIP Member
As I understand it, there is no shipped method in JDE to get a list of files in a directory. It sounds like you need to depend on the underlying OS.

In my case, I need to execute a bsfn for each file in a directory. What's the best approach?

I believe I have two options

1)execute an OS program to write the directory and file list to a table and process later with a UBE and the bsfn

2)have the OS execute the BFSN for each file in the directory via an interop method(XML,BSSN etc).

any help is appreciated.

per sig, E1 server would be OS/400

EDIT : current working solution

Code:
#ifdef JDENV_PC
   struct     _tfinddata_t c_file;
   ID          hFile = 0;   
#endif   
#ifdef JDENV_AS400
   DIR      *dir               = NULL;
   struct    dirent *de         = NULL;
   JCHAR	szd_name[255]   = { 0 };
#endif

#ifdef JDENV_PC         
   jdeStrncat(lpDS->szDirectoryPath, _J("*.*"), 4);
   if ((hFile = _tfindfirst(lpDS->szDirectoryPath, &c_file)) != -1L){  
      /*do stuff*/
      while(_tfindnext(hFile, &c_file ) == 0){ 
         /*do more stuff*/
      }
   }
#ifdef JDENV_AS400
   dir = jdeOpendir(lpDS->szDirectoryPath);
   if (dir){
      while ((de = readdir(dir)) != NULL){
         jdeToUnicode(szd_name, (ZCHAR *)de->d_name, DIM(szd_name), NULL);
         /*do stuff*/
      }
   }
   jdeClosedir(dir);
#endif
 
Last edited:
You can write a C BSFN that will list files in a directory, its just that the C API calls will be O/S specific.

If it was me I would write a C BSFN that did just that. Get a list of files in a directory, iterate over the list and call your other BSFN.

Edit 1:
Actually, if it was me. I would write a C BSFN that I could re-use. One that would get a list of files/directories in a path, store list in cache, iterate, etc.

Code:
AcmeListFilesInPathInit
   idFileListHandle
   szPath

AcmeListFilesInPathIterate
   idFileListHandle
   idCursorHandle
   cIsEndOfList
   cIsCloseCursor
   szFileName
   [attributes - is a file/folder, hidden, etc.]

AcmeListFilesInPathTerm
   idFileListHandle

(I work for a company called Acme, hence the prefix "Acme")
 
Last edited:
OK. I think I get where you are going with this. Seeing as my fat client is windows, I'll need some sort of ifdef for the different C API calls?
 
Correct. #ifdef blocks for the windows implementation and one for, in you case, AS400.
 
I have found it much easier to prototype iSeries C code on the server in a stand alone fashion rather than waiting for a server package build to find errors. I'm referring to very OS specific code like you are talking about (traversing the IFS). Once you have it working there, it's a lot easier to paste the code into your JDE BSFN. Just a thought.

Craig
 
thanks for the input craig. That makes perfect sense. Still working through the windows and cache stuff.

sadly,I am not versed in the as400.
 
Curious. Where do these folders you'll be searching exist? iSeries or Win server?
 
Good to hear you're using QNTC. Isn't it really as simple as prefixing the QNTC and using forward slashes when on the iSeries?

Code:
#ifdef AS400
   /QNTC/<windows server>/<folder>/.../
#else
   \\<windows server>\<folder>\...\
#endif

Assuming you're using ANSI standard file IO routines, something like that should be all you need.

Edit: you do need to have your E1 system user setup on your windows network with the same user and password that is used for E1. That's the magic that allows E1 to see to 'see' those windows shares from the iSeries 'seamlessly'
 
Last edited:
QNTC is fantastic. I have no issues with the pathing.

"ANSI standard file IO routines" these are different for each platform. I've got the windows done using the following


EDIT : current working solution
#ifdef JDENV_PC
....jdeStrncat(lpDS->szDirectoryPath, _J("*.*"), 4);
....if ((hFile = _tfindfirst(lpDS->szDirectoryPath, &c_file)) != -1L)
....{
........./*do stuff*/
........while(_tfindnext(hFile, &c_file ) == 0)
........{
........./*do more stuff*/
........}
....}

#ifdef JDENV_AS400
...dir = jdeOpendir(lpDS->szDirectoryPath);
...if (dir){
......while ((de = readdir(dir)) != NULL){
.........jdeToUnicode(szd_name, (ZCHAR *)de->d_name, DIM(szd_name), NULL);
........./*do stuff*/
.........}
...}
...jdeClosedir(dir);
#endif

I'm no good at using jde cache functionality so i've just created a table and plan to insert into it, then process later.
 
Last edited:
thanks for everyone's help. I got this working. used a bunch of ifdef's to include headers/variables/logic for windows and as400 platforms.
 
Back
Top