1. Martin Mueller
  2. PowerBuilder
  3. Wednesday, 19 April 2017 19:31 PM UTC

Hi all,

I have to poll a known directory for csv files (another app will send them from time to time), read them and then delete them

Example:

directory c:\data

2 files in it: abc.csv and def.csv

content abc.csv: test;01234

content def.csv: test;567

How can I get the filename of the files to import them. and how can I ask, if there are files in this directory?

Any help will be appreciated

Best regrads

Martin

* Powerbuilder 12.6 on Win10

Chris Pollach Accepted Answer Pending Moderation
  1. Wednesday, 19 April 2017 19:53 PM UTC
  2. PowerBuilder
  3. # 1

Hi Martin;

  Suggestion: Have a look at the Dirlist ( ) method in PB.

HTH

Regards ... Chris

Comment
  1. Martin Mueller
  2. Thursday, 20 April 2017 04:42 AM UTC
Hi Chris,



 



thanks for the idea, it works fine :)



regards



Martin

  1. Helpful
There are no comments made yet.
Mike S Accepted Answer Pending Moderation
  1. Wednesday, 19 April 2017 21:17 PM UTC
  2. PowerBuilder
  3. # 2

you could use a batch file to generate the list of filename(s) in the directory and call your powerbuilder application with the filename to process as a commandline parameter within the batch/command file loop.

 

 

Comment
  1. Martin Mueller
  2. Thursday, 20 April 2017 04:43 AM UTC
Hi Mike,



thanks for your help. I used the idea of Chris, I think it's more comfortable.



thanks



Martin

  1. Helpful
  1. Roland Smith
  2. Thursday, 20 April 2017 18:01 PM UTC
I have a example of the Win API function to get a file directory. The DirList function requiers a listbox control and also changes the current directory.



http://www.topwizprogramming.com/freecode_filesys.html

  1. Helpful
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Wednesday, 26 April 2017 14:20 PM UTC
  2. PowerBuilder
  3. # 3

Here's a function I created that does what you want.
Note that this editor uses a non-monospaced font so the formatting is screwy.

Olan

//*********************************************************************
// Object        :    n_cst_rpt_liblist
// Function        :    of_Get_library_list()
//
// Ancestor        :    (None)
// Access        :    public
// Arguments    :    (None)  
//
// Returns        :    String
// Throws        :    
//
// Description    :    Returns the library list for the application,
//                        including the locations where the client has placed
//                        the application-specific Report Library (PBL) that
//                        was delivered with the application.
//
//                        Example: SWAT_RPTS on "M:\Shared\Reports".
//
//********************************************************************
// Revision History
//
// Developer    Date            Version        Description
// ---------    -----------    -----------    -------------------------------
// O Knight    24-SEP-2003 3.0.1.5        Replaced listbox with PFC code.
// O Knight        09/11/2003    3.0.1.4        Initial version.
//
//********************************************************************
// Copyright © 1994-2003 Intec Telecom Systems.
//********************************************************************
boolean                lb_exists
long                    ll_rowcount, ll_row, ll_result, ll_pos, ll_idx
long                    ll_jdx, ll_count
n_cst_filesrv      inv_filesrv
n_ds                    lds
string                ls_libraries, ls_lib_path, ls_applid, ls_new
string                ls_currdir, ls_filename

n_cst_dirattrib   lnv_dirlist []

 

// Get the current set of libraries associated with this application
ls_libraries = GetLibraryList ()

f_SetFilesrv (inv_filesrv, TRUE)
ls_currdir = inv_filesrv.of_GetCurrentDirectory ()    


// Create the datastore to access the System Preferences table
lds                = CREATE n_ds
lds.DataObject = "d_rpt_system_preferences"
ll_result        = lds.SetTransObject (SQLCA)


// See if the user has any Report Library Paths defined
// in the System Preferences table (Chas.prfrnc)
FOR ll_idx = 1 TO 2
        
    IF (ll_idx = 1) THEN
        ls_applid = gnv_app.is_appl_id    // Is an application-specific path defined?
    ELSE
        SetNull (ls_applid)                    // Is a global library path defined?
    END IF
    
    
    ll_rowcount = lds.Retrieve (ls_applid)
    IF (ll_rowcount > 0) THEN
        
        // Get the library path specified
        ls_lib_path = lds.GetItemString (1, "value")
        
        // Ensure that the library path is not null
        IF (IsNull (ls_lib_path)) OR (TRIM (ls_lib_path) = "") THEN CONTINUE
    
    
        // Does the path already exist in the library list?
        ll_pos = Pos (Upper (ls_libraries), Upper (ls_lib_path))
        IF (ll_pos = 0) THEN
            
            // See if any PBLs are in this library path
            lb_exists = DirectoryExists ( ls_lib_path )
            IF (NOT (lb_exists)) THEN CONTINUE
        
            // Get the list of PBLs from this directory
            ls_new   = ls_lib_path + "\*.pbl"
            ll_count = inv_filesrv.of_DirList (ls_new, 0, lnv_dirlist)
            
            // Add these PBLs to the application's library list
            FOR ll_jdx = 1 TO ll_count
        
                // Get the next PBL listed
                ls_filename = Lower (Trim (lnv_dirlist [ll_jdx].is_filename))
                
                ls_new = ls_lib_path + "\" + ls_filename
            
                // Add the library to the application library list
                ls_libraries = ls_libraries + "," + ls_new
                
                // Increment the number of libraries added
                il_libs_added ++
            
            NEXT
            
            // Update the set of libraries for the application
            IF (ll_jdx > 0) THEN
                    
                // ---------------------------------------------------------------
                // This next step is what allows PBLs that are not associated with
                // the current application to be included in the application.  
                //
                // NOTE: YOU CANNOT TEST THIS FEATURE IN THE DEVELOPMENT IDE!!!!
                //       YOU CAN ONLY USE IT IN A RUNTIME ENVIRONMENT!!!!
                // ---------------------------------------------------------------                
                 ll_result = SetLibraryList (ls_libraries)
                
            END IF
            
        END IF
        
    END IF
    
NEXT

 

IF (IsValid (lds)) THEN DESTROY lds
IF (IsValid (inv_filesrv)) THEN DESTROY inv_filesrv

RETURN ls_libraries

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.