BookmarkSubscribeRSS Feed

[SAS 프로그래밍 고수 백승민] [외부파일] Fdelete 함수를 사용하여 외부 디렉토리 내의 파일 삭제

Started ‎06-11-2020 by
Modified ‎06-12-2020 by
Views 207

* 출처 : http://cafe.daum.net/statsas/3F8j/116

 

* http://www.statwith.pe.kr/SAS/1.FUNCTION/F_list.htm#F09;

 

* 내부의 fdelete 파일 부분의 주석문을 제거후 사용하시면 됩니다. 단, Delete문장의 위험상 사용전에 테스트후에 사용하시는 것 잊지 마시기를 바랍니다.;

 

* 현재는 디렉토리 안의 모든 파일을 삭제하는 프로그램입니다. 엑셀파일만 삭제시 안정상 "scan(upcase(name),2,'.') ne ' '" 이 부분을 "scan(upcase(name),2,'.') = 'XLS'" 로 변경하시는 것이 더 좋을 듯 합니다.;


%let myDir=c:\work;

data back;
     length name $ 40 filePath $ 200;
     * 외부파일에 대한 참조명 할당;
     rc=filename("myDir","&myDir");
     if rc=0 then do;
        * 디렉토리 Open;
        did=dopen("myDir");
        if did > 0 then do;
           * 디렉토리의 멤버수 반환;
           memcount=dnum(did);
           do i=1 to memcount;
              * 디렉터리 안의 구성원 이름 반환;
              name=dread(did,i);
              var1=scan(upcase(name),2,'.');
              * 확장자 존재시 Do문장 실행;
              if scan(upcase(name),2,'.') ne ' ' then do;
                 * 파일 경로명 생성;
                 filePath=catx('\',pathname('myDir'),name);
                 rc=filename('mkrFile',filePath);
                 if rc=0 then do;
                    * 파일을 삭제시;
                    *rc=fdelete('mkrFile');
                    if rc=0 then put 'NOTE: ' filePath 'deleted';
                    else put 'ERROR: ' filePath 'not deleted!';
                 end;
              end;
              output;
           end;
           rc=dclose(did);
        end;
        rc=filename('mkrFile',' ');
        rc=filename('myDir',' ');
      end;
run;

Version history
Last update:
‎06-12-2020 02:07 AM
Updated by:
Contributors

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Article Labels
Article Tags