Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Finding the file name with Regular Expression

Former Member
0 Likes
3,384

Hello All,

I am having some requirment to find the file name for the input provided parameter.

In my program i am having an input parameter for file name. This contains both the file name and file stored location.

Example : C:\Dokumente und Einstellungen\xs234fs\Desktop\TEST_123_44.txt

From the above example string i need to find only the file name that is TEST_123_44.txt by using Regular expression.

Please let me know how to get this.

Thank you ver much in advance.

Thanks,

Feroz.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,439

Not Sure about regular expression, but there is a FM which can split the file path:

PC_SPLIT_COMPLETE_FILENAME

Not Sure about regular expression, but there is a FM which can split the file path:

PC_SPLIT_COMPLETE_FILENAME

14 REPLIES 14
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,439

Hello,

If you have attached an F4 help to the filename input param, in that you can use the FM: GUI_FILE_SAVE_DIALOG.

In this there is a return param FILENAME which contains the name of the file.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

      CALL FUNCTION 'GUI_FILE_SAVE_DIALOG'
       EXPORTING
         window_title            = TEXT-001
         default_extension       = p_extens
         default_file_name       = ls_deffile
         initial_directory       = ls_initdet
       IMPORTING
         filename                = ls_filename "This contains the filemame
         path                    = ls_path
         fullpath                = ls_fullpath
         user_action             = ls_usaction.

Else if you have hardcoded the filename in the input field you can use rthe FM: PC_SPLIT_COMPLETE_FILENAME to split the filenames into different components

BR,

Suhas

Edited by: Suhas Saha on Mar 6, 2009 9:31 AM

Read only

Former Member
0 Likes
2,440

Not Sure about regular expression, but there is a FM which can split the file path:

PC_SPLIT_COMPLETE_FILENAME

Read only

0 Likes
2,439

also check:

SO_SPLIT_FILE_AND_PATH

CH_SPLIT_FILENAME

Read only

Former Member
0 Likes
2,439

Hi Feroz,

There are many threads with the same question on SCN. Did you search before posting ?

regards,

Advait

Read only

0 Likes
2,439

Hello Advait Gode,

I have not see any Regular expression thread related to this. I have seen function modules.

I need this by Regular Expression.

Thanks,

Feroz.

Read only

0 Likes
2,439

This message was moderated.

Read only

keerthy_k
Product and Topic Expert
Product and Topic Expert
0 Likes
2,439

Hi,

Pls see the code below:

DATA: LONG_FILENAME TYPE DBMSGORA-FILENAME,

PURE_FILENAME TYPE SDBAH-ACTID,

PURE_EXTENSION TYPE SDBAD-FUNCT.

DATA: SHIFTN TYPE I,

DEL_SLASH(1) VALUE '/',

DEL_POINT(1) VALUE '.'.

DO.

SEARCH LONG_FILENAME FOR DEL_SLASH.

IF SY-SUBRC > 0.

EXIT.

ENDIF.

SHIFTN = SY-FDPOS + 1.

SHIFT LONG_FILENAME BY SHIFTN PLACES LEFT.

ENDDO.

SPLIT LONG_FILENAME AT DEL_POINT INTO PURE_FILENAME PURE_EXTENSION.

CONDENSE PURE_FILENAME NO-GAPS.

CONDENSE PURE_EXTENSION NO-GAPS.

Keerthi

Read only

matt
Active Contributor
0 Likes
2,439

Before anyone else posts an answer, the original poster is wanting to know how do this using REGULAR EXPRESSIONS. Further references to split, or function modules will be deleted.

I'm tempted to remove the points, but seeing as the OP has seen fit to give them for the repeated wrong answers, that's up to him.

Read only

matt
Active Contributor
0 Likes
2,439

I've done a quick search on google, using keywords regex filename and it seems the best advice is to not use regex for this purpose as it is difficult construct one that catches all. I certainly couldn't find one that works.

matt

Read only

0 Likes
2,439

May i know which rule i broke while answering this question?..

Read only

0 Likes
2,439

I can't find any of your reply in the above posts.

can we smell something here ? ( If you are supporting for some other ...)

Read only

0 Likes
2,439

I am interested in possibility of finding a solution through regex expression .

I suggested a link which has been deleted.

So waiting for aRs

Read only

keerthy_k
Product and Topic Expert
Product and Topic Expert
0 Likes
2,439

Hi Feroz,

See the following FM:

CALL FUNCTION 'SPLIT_FILENAME'

EXPORTING

LONG_FILENAME = DBMSGORA-FILENAME

IMPORTING

PURE_FILENAME = LOCAL_ACTID

PURE_EXTENSION = LOCAL_FUNCT.

Here PURE_FILENAME will give the name of the file(eg ABC>DOC) as ABC and PURE_EXTENSION will give the extension as DOC.

Keerthi

Read only

Former Member
0 Likes
2,439

I was searching for the same thing but I didn't find it. It took a bit but I made one that works:

REPLACE ALL OCCURRENCES OF REGEX '[\w:\\,\\,\/][\w,\s,[:punct:]]*[\\,\/]' in l_str_file with ''.

Edited by: Erik Peterson on Jul 24, 2009 7:47 AM