C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[36857] Re:파일삭제
임문환.실업자 [origin] 1873 읽음    2004-08-19 11:54
같은 결과지만,
if(DirectoryExists(fpath)) DirRecursiveScan(fpath);를
if(sr.Attr & faDirectory) DirRecursiveScan(fpath);로 하시고.

한편, 문자열 비교를 할 때는 대소문자가 구별되므로 한 가지로 통일한 후 비교하세요.
const String file_name_to_delete("description.sdo"); //일단 소문자로 했음
if(sr.Name.LowerCase()==file_name_to_delete) DeleteFile(sr.Name);
TSearchRec::Name에는 디렉터리부분은 없고 파일이름과 확장자로만 이루어져 있습니다.

DeleteFile()이 사용하는 현재 디렉터리와 FindFile()/FindNext()가 사용하는 현재 디렉터리가 상호 일치하면 DeleteFile에 디렉터리를 지정하지 않아도 됩니다. 그 것은 쉽지 않은 확율이므로 DeleteFile()의 매개변수에 지정하는 파일이름은 완전한 경로여야 합니다.
즉, 아래 1 또는 2로 해야 합니다. 
1. DirRecursiveScan(String path)의 선두 부분에 curpath = ExtractFilePath(path);를 추가
if(sr.Name.LowerCase()==file_name_to_delete) DeleteFile(curpath+sr.Name);

2. if(sr.Name.LowerCase()==file_name_to_delete) DeleteFile(path+sr.Name);

님의 코드에 다른 문제가 있는지 다 살펴보지는 않았음을 말씀드리며
잘 안 되면 계속 질문하시기 바랍니다.


최진호 님이 쓰신 글 :
: 간단한 프로그램 같은데..
:
: 잘안되네요..
:
: 디렉토리와 서브 폴더에서 description.sdo 파일을 발견하면
:
: 삭제하는 프로그램을 만들려고 하는데..잘안되네요..
:
: 고수님의 조언을 부탁드립니다...
:
:
: void __fastcall TForm1::DirRecursiveScan(String path)
: {
:         //TODO: Add your source code here
:         try
:   {
:     if(String(path.AnsiLastChar()) != "\\") path += "\\";
:     AnsiString fpath, SaveEn, currpath, Filename;
:     TSearchRec sr;
:     char *pszBuffer;
:     int inFile;
:     int iFileLen;
:
:     int Found = FindFirst(path + "*.*", faArchive | faDirectory, sr);
:
:     while(Found == 0)
:     {
:       fpath = path + sr.Name;
:       if(*sr.Name.c_str() != '.')
:       {
:         if(DirectoryExists(fpath)) DirRecursiveScan(fpath);
:         else
:         {
:
:          if(sr.Name=="description.sdo")
:           {
:             DeleteFile(sr.Name);
:           }
:          }
:         }
:       Found = FindNext(sr);
:     }
:     FindClose(sr);
:   }
:   catch(Exception *e)
:   {
:     throw e;
:   }
:
:
: }
:
: void __fastcall TForm1::Button1Click(TObject *Sender)
: {
:  String path ="c:\\ex1";
:  DirRecursiveScan(path);
:  ShowMessage(" 작업이 완료됨");
: }

+ -

관련 글 리스트
36851 파일삭제 최진호 1144 2004/08/19
36857     Re:파일삭제 임문환.실업자 1873 2004/08/19
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.