Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


List contents of a directory/folder in Powerbuilder.

Posted on 2004-10-14
Medium Priority
Last Modified: 2013-12-26
Hi there.
I want a way to retrieve a list of all the files in a chosen directory or folder.

Pretty much any format will do, although something like an array of filenames and metadata such as dates would probably be the best.

The overall goal will be to generate a list of .sql files in \\server\folder\ and read the contents of each file so they can be executed against a database.

Using a Windows API call or whatever is fine.  I am using Windows 2000.

Thank you for your time.

Question by:akadruid
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 33

Accepted Solution

sajuks earned 1500 total points
ID: 12306832
You can use the dirlist() function to get the directory into a listbox

Author Comment

ID: 12307269
That does what I want.

Not perfect, since it requires a visual object and bit of playing around, but good enough.

In case anyone else cares, this quick and dirty code (below) will read the first file name.  You can adjust it to loop through lb_1.TotalItems() to give you all the filenames.

uint li_filetype
string ls_file_pattern

ls_file_pattern = "\\server\share\"
lb_1.Reset ()
if lb_1.DirList ( ls_file_pattern, li_filetype ) then
      lb_1.SelectItem (1)
      //Messagebox ("First item is:", lb_1.SelectedItem ())
      Messagebox ("Can't read from:", ls_file_pattern)
end if

In all the years I've been working with pb, I have never seen that function!  Probably because I don't use listboxes normally.

Expert Comment

ID: 12335421
Dear Friend,
  Try out this, Ive written and used  for updating the application at the client system, by a single click of button, which has this following code.

Declare this API-Function in Application's Global Function Declaration Area

Function boolean CopyFile (string lpExistingFileName, ref string lpNewFileName, boolean b) Library "KERNEL32.DLL" Alias for "CopyFileA"

String  ls_source, ls_dll, ls_pbd, ls_app, ls_all, ls_destination
String ls_path
String  ls_complete_path

ls_pbd = '\\souce_system\spts_test\*.pbd'
ls_path = '\\source_system\spts_test\'
ls_destination = "C:\Spts\"

ddlb_dir_details.DirList(ls_pbd, 0)

If ddlb_dir_details.TotalItems() > 0 Then
      For ii_row = 1 to ddlb_dir_details.TotalItems()
       is_source_file_name = ddlb_dir_details.Text(ii_row)
       ls_destination = ls_destination + is_source_file_name
       is_source_file_name = ls_path + is_source_file_name
      MessageBox("Error","Copying Default Pbds Failure")
End IF

with the slight modification to this code, you can get the list of files to the list box.

   after getting the list of files, you can take the selected file and continue as
String ls_search
ls_search = "c:\abc.txt"
if FileExists(ls_search) then
    ls_file = ls_file_2
    string     ls_shortpath, ls_file_contents
    long     ll_max_length
    ll_max_length = 255
    ls_shortpath = space(ll_max_length)
    long     ll_length
//windows API to get the dos-name(short name) and path if you know the window name
    ll_length = GetShortPathName (ls_search, ls_shortpath, ll_max_length)
    Integer li_FileNum
//Check out to find the file exists before proceeding, you can use ls_search(window name) or
//ls_shortpath(Dos Name) as you need
    li_FileNum = FileOpen(ls_search,StreamMode!,Read!,LockWrite!)
//if exists aplly the wite lock to it
       IF li_FileNum > 0  THEN
           FileRead ( li_FileNum , ls_file_contents )
           FileClose (li_FileNum)
       End If
End IF

All the best,

Konka Kiran Kumar

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question