Application Development 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: 

Delete directory

Former Member
0 Kudos
291

Hi all,

i want to delete a directory (a folder ) in a drive..i have written code but seems not working..

DATA : V_VALUE1 TYPE STRING.

DATA : V_RETURN_CODE1 TYPE I.

CONCATENATE 'C:\PO PDFs\' P_OBJ_ID '.pdf' INTO V_VALUE1.

CLEAR : P_OBJ_ID.

...................DELETE THE DIRECTORY PO PDFs......................

CREATE OBJECT V_GUIOBJ.

CALL METHOD V_GUIOBJ->directory_delete

EXPORTING

directory = V_VALUE1

changing

rc = V_RETURN_CODE1

EXCEPTIONS

DIRECTORY_DELETE_FAILED = 1

CNTL_ERROR = 2

ERROR_NO_GUI = 3

PATH_NOT_FOUND = 4

DIRECTORY_ACCESS_DENIED = 5

UNKNOWN_ERROR = 6

NOT_SUPPORTED_BY_GUI = 7

WRONG_PARAMETER = 8

others = 9

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Please hlp

1 ACCEPTED SOLUTION

Former Member
0 Kudos
100

Hi

Where have you defined the object V_GUIOBJ?

The path is 'C:\PO PDFs\' P_OBJ_ID '.pdf' so it seems you're deleting a PDF file not a path.

Do you want to delete a file or a directory?

For the file you can use the method FILE_DELETE.

Max

5 REPLIES 5

Former Member
0 Kudos
101

Hi

Where have you defined the object V_GUIOBJ?

The path is 'C:\PO PDFs\' P_OBJ_ID '.pdf' so it seems you're deleting a PDF file not a path.

Do you want to delete a file or a directory?

For the file you can use the method FILE_DELETE.

Max

Former Member
0 Kudos
100

Hi Srikanth,

There seems to be one more Single quote in filename , remove that and checkout if it works

change this

CONCATENATE 'C:\PO PDFs\' P_OBJ_ID <b>'.</b>pdf' INTO V_VALUE1.

to

CONCATENATE 'C:PO PDFsP_OBJ_ID.pdf' INTO V_VALUE1.

Message was edited by:

Chandrasekhar Jagarlamudi

Former Member
0 Kudos
100

Hi,

Instead of this, you try following method, give appropirate parameter and it will do.

CALL METHOD cl_gui_frontend_services=>directory_delete

EXPORTING

directory =

changing

rc =

*EXCEPTIONS

*DIRECTORY_DELETE_FAILED = 1

*CNTL_ERROR = 2

*ERROR_NO_GUI = 3

*PATH_NOT_FOUND = 4

*DIRECTORY_ACCESS_DENIED = 5

*UNKNOWN_ERROR = 6

*NOT_SUPPORTED_BY_GUI = 7

*WRONG_PARAMETER = 8

*others = 9

.

IF sy-subrc <> 0.

*MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Hope it will help you.

former_member181962
Active Contributor
0 Kudos
100

The proble is that you are trying to create an object wthout declaring a referance to the class:

You can directly call the class method like this:

CALL METHOD cl_gui_frontend_services=>directory_delete

EXPORTING

directory = 'C:/PO PDFs'

changing

rc = v_subrc

EXCEPTIONS

DIRECTORY_DELETE_FAILED = 1

CNTL_ERROR = 2

ERROR_NO_GUI = 3

PATH_NOT_FOUND = 4

DIRECTORY_ACCESS_DENIED = 5

UNKNOWN_ERROR = 6

NOT_SUPPORTED_BY_GUI = 7

WRONG_PARAMETER = 8

others = 9

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Regards,

Ravi

0 Kudos
100

when i use this FM..i went in debug mode ...it is giving as <b>access_denied</b> exception...

From SAP i can't access to local PC?

Do SAP provides a default folder that i can save a file and delete that file ??

Pls Help