On 17-9-2015 16:19, 'stwizard' [email protected] [firebird-support] wrote:
> Firebird v1.5.3 and v2.5.4

For Firebird 2.5 it is simpler than for Firebird 1.5.

> I need a way to extract just the file name for a given file path either
> by code in a stored procedure or by calling a UDF in the stored procedure.
>
> Example, I need to extract “SNKSAid.dat” from
> “K\Frontline\Documents\Aids\SNKSAid.dat”
>
> Any ideas?

I Firebird 2.5 you can do:

EXECUTE BLOCK RETURNS (filename VARCHAR(1024))
AS
DECLARE filepath VARCHAR(1024);
DECLARE searchIndex int;
DECLARE previousIndex int;
BEGIN
     filepath = 'K:\Frontline\Documents\Aids\SNKSAid.dat';
     previousIndex = 0;
     searchIndex = position('\', filepath);

     WHILE (searchIndex > 0) DO
     BEGIN
         previousIndex = searchIndex;
         searchIndex = position('\', filepath, previousIndex + 1);
     END

     filename = substring(filepath from previousIndex + 1);
     SUSPEND;
END

For Firebird 1.5, you would need to find equivalent UDFs for position 
and substring (and of course you can't use execute block in 1.5, but I 
only used it to demonstrate the solution).

Mark
-- 
Mark Rotteveel

Reply via email to