2005 Jul 07 4:52 PM
Hi Gurus,
I am facing a problem,the rquirement is to First read an directory & then inside that directory ,I need to trad file.
there exist a fn module which reads from file from the directory.But if any sub directory also exist in that main directory ,then it raises an exception.
Can any one provide a way out to read directory first & subsequently a file in that directory,assuming that sub directories too exist in main directory.
Thanks for all forthcoming responses.
Regards,
Gaurav
2005 Jul 07 5:52 PM
Hi Gaurav,
pls try function module 'EPS_GET_DIRECTORY_LISTING'.
I hope it helps. BR,
Alvaro
Hi Gurus,
I am facing a problem,the rquirement is to First read an directory & then inside that directory ,I need to trad file.
there exist a fn module which reads from file from the directory.But if any sub directory also exist in that main directory ,then it raises an exception.
Can any one provide a way out to read directory first & subsequently a file in that directory,assuming that sub directories too exist in main directory.
Thanks for all forthcoming responses.
Regards,
Gaurav
2005 Jul 07 5:51 PM
Hi,
From inside your code, you can run a script as an OS level command (not an elegant option) that does some of the work for you. For example, you can create a directory listing (using commands like ls or dir << in the script) into a text file and store this text file in a specified location where there is no subdirectory. You can then read this text file using standard commands(open dataset) to get all the file locations. Finally, you have the complete path and the filename in your program, so you can choose to read the required file (open dataset).
There must certainly be some FM that handles it, but this will also do.
cheers,
2005 Jul 07 5:52 PM
Hi Gaurav,
pls try function module 'EPS_GET_DIRECTORY_LISTING'.
I hope it helps. BR,
Alvaro
2005 Jul 07 9:08 PM
Hi,
This FM 'EPS_GET_DIRECTORY_LISTING' requires Basis authorisations hence it maynot be a good option. I once had issues with this authorisations and later had to use the External OS command created in SM69. Use FM SXPG_COMMAND_EXECUTE to run the external OS commands
Deepak
2005 Jul 08 7:31 AM
Hi Gaurav,
in fm EPS_GET_DIRECTORY_LISTING there're bugs , if you're searching with wildcards- so best solution ist to use sm69 , as Deepak writes, with unix command <b>find</b>.
example: find /home -name abc.txt -print
regards Andreas
2005 Jul 08 7:43 AM
Hi,
You can also call some internal functions to retrieve a dir listing:
report zdirlist .
types: begin of tfile,
dirname(75) type c, " name of directory. (possibly truncated.)
name(75) type c, " name of entry. (possibly truncated.)
type(10) type c, " type of entry.
len(8) type p, " length in bytes.
owner(8) type c, " owner of the entry.
mtime(6) type p, " last modification date, seconds since 1970
mode(9) type c, " like "rwx-r-x--x": protection mode.
errno(3) type c,
errmsg(40) type c,
end of tfile.
data: lv_eps_subdir like epsf-epssubdir.
data: dir_list type table of tfile
with header line,
file_counter type i,
error_counter type i,
field_counter type i.
field-symbols: <f>.
parameters: dir_name like epsf-epsdirnam,
filemask like epsf-epsfilnam.
Start
get directory listing
call 'C_DIR_READ_FINISH' " just to be sure
id 'ERRNO' field dir_list-errno
id 'ERRMSG' field dir_list-errmsg.
call 'C_DIR_READ_START'
id 'DIR' field dir_name
id 'FILE' field filemask
id 'ERRNO' field dir_list-errno
id 'ERRMSG' field dir_list-errmsg.
if sy-subrc <> 0.
raise read_directory_failed.
endif.
refresh dir_list.
clear file_counter.
clear error_counter.
do.
clear dir_list.
call 'C_DIR_READ_NEXT'
id 'TYPE' field dir_list-type
id 'NAME' field dir_list-name
id 'LEN' field dir_list-len
id 'OWNER' field dir_list-owner
id 'MTIME' field dir_list-mtime
id 'MODE' field dir_list-mode
id 'ERRNO' field dir_list-errno
id 'ERRMSG' field dir_list-errmsg.
if sy-subrc = 0.
add 1 to file_counter.
append dir_list.
elseif sy-subrc = 1.
exit.
else.
if error_counter > 100.
call 'C_DIR_READ_FINISH'
id 'ERRNO' field dir_list-errno
id 'ERRMSG' field dir_list-errmsg.
write: / 'Too many read errors'.
exit.
endif.
add 1 to error_counter.
append dir_list.
endif.
enddo.
call 'C_DIR_READ_FINISH'
id 'ERRNO' field dir_list-errno
id 'ERRMSG' field dir_list-errmsg.
if file_counter > 0.
sort dir_list by name ascending.
else.
write: / 'Empty directory'.
endif.
loop at dir_list.
clear field_counter.
write: /.
do.
add 1 to field_counter.
assign component field_counter
of structure dir_list to <f>.
if not sy-subrc is initial.
exit.
endif.
write: <f>, ' '.
enddo.
endloop.
However, I don't know if there are special user rights required and how portable this is...
Hope this helps (please reward me if it does ,
Joerg
2005 Jul 21 7:09 AM
Hi floks,
thansk for all your help.
I am rewarding you your due.
Just to share fm 'RZL_READ_DIR_LOCAL' did the trick for me.
Regards,
Gaurav
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |