Solved

List contents of a directory/folder in Powerbuilder.

Posted on 2004-10-14
3
5,311 Views
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.

akaDruid
0
Comment
Question by:akadruid
[X]
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
3 Comments
 
LVL 33

Accepted Solution

by:
sajuks earned 500 total points
ID: 12306832
You can use the dirlist() function to get the directory into a listbox
0
 
LVL 1

Author Comment

by:akadruid
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

li_filetype=39
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 ())
else
      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.
0
 

Expert Comment

by:Konka_Kiran
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"

SetPointer(HourGlass!)
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
       CopyFile(is_source_file_name,ls_destination,False)
       SetNull(ls_destination)
       SetNull(is_source_file_name)
     Next
Else
      MessageBox("Error","Copying Default Pbds Failure")
      Return
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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. …
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

740 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