Hi,
have you checked the code in FM
/SAPDMC/LSM_F4_SERVER_FILE
It should help you get the logic to get to the desired directory. Also check the code in FM EPS2_GET_DIRECTORY_LISTING This does do a filtering function using the C Function calls that you are using.
Cheers,
Arindam