Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read a folder/directory

Status
Not open for further replies.

rudyboy

Programmer
Oct 16, 2003
49
PH
Hi everyone,

I am developing a module that will read a certain folder from a network. Is it possible to browse a folder programatically(without opening a window) so that I can get only the files that I need. For example in a folder named 'SAMPLE', I will get only all text files.


Thanks

 
Sure it's possible (at least in PowerBuilder 9, because i use functions on directory and filecopy).

i create a listbox (lb_filelist) and make it invisible then make this example of code :

Code:
string  ls_path="tektips"
string ls_loc
integer li_filenum

string ls_fileext = "*.TXT"
integer Total, n

ls_loc = getcurrentdirectory()

li_filenum = ChangeDirectory( "C:\" )
li_filenum = CreateDirectory ( ls_path )
li_filenum = ChangeDirectory( ls_loc )

lb_filelist.DirList(ls_fileext, 0)
Total = lb_filelist.TotalItems()

FOR n = 1 to Total

li_FileNum = FileCopy (lb_filelist.text(n) , "C:\tektips\" + lb_filelist.text(n), TRUE)

NEXT

Hope this will help
 
Hello rudyboy!

There is an object that I use when coding in VB that allows me to access the folder directory and execute all sorts of functions. Since powerbuilder can use objects the same as VB, I don't see any reason why this won't work. I havn't actually tried this :).
Code:
OLEObject objFileSys, objFile
objFileSys = CREATE oleobject
objFileSys.ConnectToNewObject("Scripting.FileSystemObject")

For Each objFile In objFileSys.GetFolder("path").Files
    MessageBox("test", objFile.Path)
Next
objFileSys.disconnectobject()
If you want more documentation on this, check out MSDN and do a search for file system object. You'll have to let me know if it works!

Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top