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

parse file name from string

former_member194669
Active Contributor
0 Likes
611

Hi,

I am using FTP_COMMAND to get list of files from FTP server directory


  call function 'FTP_COMMAND'
    exporting
      handle        = hdl
      command       = 'ls /pub'  " << List of files in FTP dir
      compress      = compress
    tables
      data          = result
    exceptions
      command_error = 1
      tcpip_error   = 2.

I need to check whether file exist in the FTP server directory before i am going to write.

My problem after te FTP_COMMAND i am getting a result as mentioned below. So from this result i need to PARSE the filename separetely. I like to know any function module out there, it will give the filename parsed


ls /pub
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x    9 40       20232        4096 May 24  2007 list
drwxrwxr-x    3 40       49           4096 Mar 31 14:57 details
-rw-rw-r      1 40       49          75597 Mar 31 13:23 yatt6010.2008022020080320.dat
-rw-rw-r      1 40       49          75597 Mar 31 13:28 yatt6010.2008022020080321.dat
226 Directory send OK.

a®

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
551
REPORT zz_temp.

DATA l_s_unix_dir(80)    TYPE c.
DATA l_t_unix_dir        LIKE TABLE OF l_s_unix_dir.
DATA l_v_regex(80)       TYPE c VALUE '\S+\s+\d+\s+\d+\s+\d+\s+\d+\s+\S+\s+\d+\s+(?:\d{4}|\d+:\d+)\s+(\S+)'.
DATA l_v_submatch(80)    TYPE c.


l_s_unix_dir = 'drwxr-xr-x    9 40       20232        4096 May 24  2007 list'.
APPEND l_s_unix_dir TO l_t_unix_dir.
l_s_unix_dir = 'drwxrwxr-x    3 40       49           4096 Mar 31 14:57 details'.
APPEND l_s_unix_dir TO l_t_unix_dir.
l_s_unix_dir =  '-rw-rw-r      1 40       49          75597 Mar 31 13:23 yatt6010.2008022020080320.dat'.
APPEND l_s_unix_dir TO l_t_unix_dir.
l_s_unix_dir =  '-rw-rw-r      1 40       49          75597 Mar 31 13:28 yatt6010.2008022020080321.dat'.
APPEND l_s_unix_dir TO l_t_unix_dir.


LOOP AT l_t_unix_dir INTO l_s_unix_dir.
  FIND FIRST OCCURRENCE OF REGEX l_v_regex IN l_s_unix_dir SUBMATCHES l_v_submatch.
  WRITE:/ l_v_submatch.
ENDLOOP.
3 REPLIES 3
Read only

Former Member
0 Likes
552
REPORT zz_temp.

DATA l_s_unix_dir(80)    TYPE c.
DATA l_t_unix_dir        LIKE TABLE OF l_s_unix_dir.
DATA l_v_regex(80)       TYPE c VALUE '\S+\s+\d+\s+\d+\s+\d+\s+\d+\s+\S+\s+\d+\s+(?:\d{4}|\d+:\d+)\s+(\S+)'.
DATA l_v_submatch(80)    TYPE c.


l_s_unix_dir = 'drwxr-xr-x    9 40       20232        4096 May 24  2007 list'.
APPEND l_s_unix_dir TO l_t_unix_dir.
l_s_unix_dir = 'drwxrwxr-x    3 40       49           4096 Mar 31 14:57 details'.
APPEND l_s_unix_dir TO l_t_unix_dir.
l_s_unix_dir =  '-rw-rw-r      1 40       49          75597 Mar 31 13:23 yatt6010.2008022020080320.dat'.
APPEND l_s_unix_dir TO l_t_unix_dir.
l_s_unix_dir =  '-rw-rw-r      1 40       49          75597 Mar 31 13:28 yatt6010.2008022020080321.dat'.
APPEND l_s_unix_dir TO l_t_unix_dir.


LOOP AT l_t_unix_dir INTO l_s_unix_dir.
  FIND FIRST OCCURRENCE OF REGEX l_v_regex IN l_s_unix_dir SUBMATCHES l_v_submatch.
  WRITE:/ l_v_submatch.
ENDLOOP.
Read only

0 Likes
551

Jerry,

This is what i am looking for.

You saved my day.

Thanks

a®

Read only

0 Likes
551

Happy to do it. It is an ugly regex and I can probably do better. But it is late and time to go home