เรามีวิธีการค้นหาไฟล์ตามโฟลเดอร์ต่างๆได้โดยการเรียกใช้ ฟังก์ชั่น API หรือ ใช้คำสั่งของ PowerBuilder ก็ได้ และสำหรับผู้ที่ใช้ PFC ก็ให้ไปดูที่ pfc_n_cst_filesrvwin32
สำหรับรูปแบบของฟังก์ชั่น API ก็มีดังนี้
Function long FindFirstFileA (ref string filename, ref os_finddata findfiledata) library "KERNEL32.DLL"
โดยมีการกำหนด Structure ดังนี้
type os_finddata from structure
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]
end type
type os_filedatetime from structure
unsignedlong ul_lowdatetime
unsignedlong ul_highdatetime
end type
และสำหรับคำสั่งของ PowerBuilder เองก็เรียกใช้ FileExist โดยฟังก์ชั่นนี้จะทำการตรวจสอบและคืนค่าออกมาว่าพบหรือไม่ ถ้าค่าที่ได้รับคืนมาคือ true แสดงว่ามีไฟล์นั้นอยู่ แต่ถ้าหากว่า เป็น false แสดงว่าไม่พบไฟล์นั้น และถ้าหากว่าไฟล์นั้นถูก lock โดยโปรแกรมอื่นก็จะเกิด sharing violation และค่า false สำหรับตัวอย่างนี้ผมตัดมาจาก help ของ PB เอง
string ls_docname, ls_named
integer li_ret
boolean lb_exist
GetFileSaveName("Select File," ls_docname,ls_named, "pbl", "Doc Files (*.DOC),*.DOC")
lb_exist = FileExists(ls_docname)
IF lb_exist THEN li_ret = MessageBox("Save", "OK to write over" + ls_docname, Question!, YesNo!)


