안녕하세요?
배치파일은 아니고 원하시는 기능의 함수입니다. path의 하위폴더에 있는 파일까지 삭제해 줍니다.
procedure ClearFiles( Path, SearchName: String );
var
Directory: string;
FileInfo : TSearchRec;
Found : integer;
begin
Directory:= Path;
if Path[Length(Path)] <> '' then Directory := Path + '';
Found := FindFirst(Directory + SearchName, faAnyFile, FileInfo);
while Found = 0 do
begin
if (FileInfo.Attr <> faDirectory) and (FileInfo.Name[1] <> '.') then
if FileInfo.FindData.cAlternateFileName <> '' then
DeleteFile(Directory + FileInfo.FindData.cAlternateFileName)
else
DeleteFile(Directory + FileInfo.FindData.cFileName);
Application.ProcessMessages;
Found := FindNext(FileInfo);
end;
FindClose(FileInfo);
if FindFirst(Directory + '*.*', faDirectory, FileInfo) = 0 then
begin
repeat
if ((FileInfo.Attr and faDirectory) = faDirectory) and (FileInfo.Name[1]<>'.') then
begin
ClearFiles(Directory+FileInfo.Name+'', SearchName); // 재귀호출
end;
Application.ProcessMessages;
until (FindNext(FileInfo) <> 0);
end;
안녕하세요?
배치파일은 아니고 원하시는 기능의 함수입니다. path의 하위폴더에 있는 파일까지 삭제해 줍니다.
procedure ClearFiles( Path, SearchName: String );
var
Directory: string;
FileInfo : TSearchRec;
Found : integer;
begin
Directory:= Path;
if Path[Length(Path)] <> '' then Directory := Path + '';
Found := FindFirst(Directory + SearchName, faAnyFile, FileInfo);
while Found = 0 do
begin
if (FileInfo.Attr <> faDirectory) and (FileInfo.Name[1] <> '.') then
if FileInfo.FindData.cAlternateFileName <> '' then
DeleteFile(Directory + FileInfo.FindData.cAlternateFileName)
else
DeleteFile(Directory + FileInfo.FindData.cFileName);
Application.ProcessMessages;
Found := FindNext(FileInfo);
end;
FindClose(FileInfo);
if FindFirst(Directory + '*.*', faDirectory, FileInfo) = 0 then
begin
repeat
if ((FileInfo.Attr and faDirectory) = faDirectory) and (FileInfo.Name[1]<>'.') then
begin
ClearFiles(Directory+FileInfo.Name+'', SearchName); // 재귀호출
end;
Application.ProcessMessages;
until (FindNext(FileInfo) <> 0);
end;
FindClose(FileInfo);
end;
사용법
ClearFiles('c:temp', '*.txt');