tags:

views:

121

answers:

2
+2  Q: 

Powerbuilder query

How I can serach a .txt file in any directoty(i.e. c:\,d:\ etc.) using file functions in power bulilder.

+1  A: 

You can use a ListBox control to get a list of files/directories based on a given string pattern (*.txt, myfile.txt, .etc). Look at the DirList function in the help. And here is an example from here showing how to use a ListBox control without putting it visually on a window.

string ls_files[]
window lw_1
listbox llb_1
int li_items, li_i

Open( lw_1 )

lw_1.openUserObject( llb_1 )

llb_1.DirList( sFileSpec, uFileType )

li_items = llb_1.TotalItems()

For li_i = 1 to li_items

ls_files[ li_i ] = llb_1.Text( li_i )

Next

lw_1.closeUserObject( llb_1 )

Close( lw_1 )
Dougman
It is very annoying that you have to have a control on a window for the DirList to work. It adds unnecessary steps, especially when I'm working from an NVO.
Adam Hawkes
+1  A: 

So, if all you're doing is looking for files, you can do this with a listbox.DirList(), or if you want to do this without being tied to a window or a control, you can call WinAPI functions to do this:

Function long FindFirstFileW (ref string filename, ref os_finddata findfiledata) library "KERNEL32.DLL" alias for "FindFirstFileW"
Function boolean FindNextFileW (long handle, ref os_finddata findfiledata) library "KERNEL32.DLL" alias for "FindNextFileW"

where os_finddata is defined as

unsignedlong        ul_fileattributes
os_filedatetime     str_creationtime
os_filedatetime     str_lastaccesstime
os_filedatetime     str_lastwritetime
unsignedlong        ul_filesizehigh
unsignedlong        ul_filesizelow
unsignedlong        ul_reserved0
unsignedlong        ul_reserved1
character       ch_filename[260]
character       ch_alternatefilename[14]

and os_filedatetime is defined as

unsignedlong        ul_lowdatetime
unsignedlong        ul_highdatetime

If you want examples of how to use these, look in PFC (PowerBuilder Foundation Classes, available at CodeXchange) at the object (pfcapsrv.pbl)pfc_n_cst_filesrvunicode.of_DirList (). (That's where these prototypes and the structures are copied from, BTW.)

Good luck,

Terry

Terry