Solved

List contents of a directory/folder in Powerbuilder.

Posted on 2004-10-14
3
4,878 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
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now