文件夹的判断与创建
Posted 独吊东南枝
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了文件夹的判断与创建相关的知识,希望对你有一定的参考价值。
PARAMETERS:l_file TYPE localfile.
DATA:status TYPE c.
*保存文件夹路径
DATA:BEGIN OF folder OCCURS 0,
dire TYPE localfile,
END OF folder.
*保存文件夹路径识别符号
DATA:BEGIN OF sign OCCURS 0,
sig TYPE c,
END OF sign.
START-OF-SELECTION.
CLEAR:folder[],sign[],status.
*新增文件夹路径识别符号,如果没有相关符号则辨别为无效路径
sign-sig = ‘/‘.
APPEND sign.
sign-sig = ‘\‘.
APPEND sign.
SEARCH l_file FOR sign.
*判断文件夹路径字符串是否有效,无效则提示错误并退出
IF sy-subrc <> 0.
MESSAGE e001(00) WITH ‘Not valuable directory‘.
EXIT.
ELSE.
*检查该文件夹路径是否已经保存
PERFORM checkdir USING l_file CHANGING status.
IF status = 1.
MESSAGE i001(00) WITH ‘The Directory is exit!‘.
EXIT.
ENDIF.
ENDIF.
SPLIT l_file AT sign INTO TABLE folder.
READ TABLE folder INDEX 1.
l_file = folder-dire."内表的第一行为盘符
*循环读取文件夹字符,检查该路径是否存在,若不存在则创建
LOOP AT folder.
IF sy-tabix > 1.
CONCATENATE l_file ‘\‘ folder-dire INTO l_file.
PERFORM checkdir USING l_file CHANGING status.
IF status = 0.
PERFORM createdir USING l_file.
ENDIF.
ENDIF.
ENDLOOP.
***************************************************************************
* 调用函数检查路径是否存在,若存在函数返回‘1‘,否则返回’0‘。 *
***************************************************************************
FORM checkdir USING dir TYPE localfile CHANGING ret TYPE c.
CALL FUNCTION ‘WS_QUERY‘
EXPORTING
filename = dir
query = ‘DE‘
IMPORTING
return = ret "1 Success 0 Fail"
EXCEPTIONS
inv_query = 1
no_batch = 2
frontend_error = 3
OTHERS = 4.
ENDFORM. "checkdir
***************************************************************************
* 调用函数根据路径创建文件夹。 *
***************************************************************************
FORM createdir USING dir TYPE localfile.
CALL FUNCTION ‘GUI_CREATE_DIRECTORY‘
EXPORTING
dirname = dir
EXCEPTIONS
failed = 1
OTHERS = 2.
WRITE: / ‘Create director success,Path:‘,dir.
ENDFORM. "createdir
以上是关于文件夹的判断与创建的主要内容,如果未能解决你的问题,请参考以下文章