ShellApi 의 Shell Operation을 이용.
클래스의 static method로 구현.
에러메세지고 뭐고 닥치고 동작수행하는 버전.
자세한 내용은 아래 링크 참조.
ShFileOperation : http://msdn.microsoft.com/en-us/library/bb762164(VS.85).aspx
ShFileOpStruct : http://msdn.microsoft.com/en-us/library/bb759795(v=VS.85).aspx
주의할 점은,
pFrom, pTo 는 String의 리스트라서 각 문자열은 null char로 구분하며, 리스트의 끝은 2개의 null char가 필요함.
리스트로 안해서 그런지 그냥 PWideChar 컨버팅으로 그냥 됨...-_-;
TDir.Delete('삭제할 디렉토리 경로'); <- 이런식으로 사용.
unit uDir;
interface
uses
SysUtils, ShellApi;
type
TDir=class
public
class function FileOperation(Op: Integer; PathFrom, PathTo: String): Boolean;
class function Delete(const Path: String): Boolean;
class function Copy(const PathFrom, PathTo: String): Boolean;
class function Move(const PathFrom, PathTo: String): Boolean;
class function Rename(const PathFrom, PathTo: String): Boolean;
end;
implementation
{ TDir }
// 삭제
// _____________________________________________________________________________
class function TDir.Delete(const Path: String): Boolean;
begin
Result:=FileOperation(FO_DELETE, Path, '');
end;
// 복사
// _____________________________________________________________________________
class function TDir.Copy(const PathFrom, PathTo: String): Boolean;
begin
Result:=FileOperation(FO_COPY, PathFrom, PathTo);
end;
// 이동
// _____________________________________________________________________________
class function TDir.Move(const PathFrom, PathTo: String): Boolean;
begin
Result:=FileOperation(FO_MOVE, PathFrom, PathTo);
end;
// 이름바꾸기
// _____________________________________________________________________________
class function TDir.Rename(const PathFrom, PathTo: String): Boolean;
begin
Result:=FileOperation(FO_RENAME, PathFrom, PathTo);
end;
// File Operation
// _____________________________________________________________________________
class function TDir.FileOperation(Op: Integer; PathFrom, PathTo: String): Boolean;
var FileOpStruct: TShFileOpStruct;
begin
FileOpStruct.Wnd:=0;
FileOpStruct.wFunc:=Op;
FileOpStruct.pFrom:=PWideChar(ExcludeTrailingPathDelimiter(PathFrom));
FileOpStruct.pTo:=PWideChar(ExcludeTrailingPathDelimiter(PathTo));
FileOpStruct.fFlags:=FOF_NOCONFIRMATION or FOF_SILENT or FOF_NOERRORUI;
FileOpStruct.lpszProgressTitle:=nil;
Result:=ShFileOperation(FileOpStruct)=0;
end;
end.
interface
uses
SysUtils, ShellApi;
type
TDir=class
public
class function FileOperation(Op: Integer; PathFrom, PathTo: String): Boolean;
class function Delete(const Path: String): Boolean;
class function Copy(const PathFrom, PathTo: String): Boolean;
class function Move(const PathFrom, PathTo: String): Boolean;
class function Rename(const PathFrom, PathTo: String): Boolean;
end;
implementation
{ TDir }
// 삭제
// _____________________________________________________________________________
class function TDir.Delete(const Path: String): Boolean;
begin
Result:=FileOperation(FO_DELETE, Path, '');
end;
// 복사
// _____________________________________________________________________________
class function TDir.Copy(const PathFrom, PathTo: String): Boolean;
begin
Result:=FileOperation(FO_COPY, PathFrom, PathTo);
end;
// 이동
// _____________________________________________________________________________
class function TDir.Move(const PathFrom, PathTo: String): Boolean;
begin
Result:=FileOperation(FO_MOVE, PathFrom, PathTo);
end;
// 이름바꾸기
// _____________________________________________________________________________
class function TDir.Rename(const PathFrom, PathTo: String): Boolean;
begin
Result:=FileOperation(FO_RENAME, PathFrom, PathTo);
end;
// File Operation
// _____________________________________________________________________________
class function TDir.FileOperation(Op: Integer; PathFrom, PathTo: String): Boolean;
var FileOpStruct: TShFileOpStruct;
begin
FileOpStruct.Wnd:=0;
FileOpStruct.wFunc:=Op;
FileOpStruct.pFrom:=PWideChar(ExcludeTrailingPathDelimiter(PathFrom));
FileOpStruct.pTo:=PWideChar(ExcludeTrailingPathDelimiter(PathTo));
FileOpStruct.fFlags:=FOF_NOCONFIRMATION or FOF_SILENT or FOF_NOERRORUI;
FileOpStruct.lpszProgressTitle:=nil;
Result:=ShFileOperation(FileOpStruct)=0;
end;
end.
'Delphi' 카테고리의 다른 글
[Delphi] DLL의 폼을 Splash 윈도우로 사용하기 (CreateParams) (0) | 2010.07.08 |
---|---|
[Delphi] 실행파일이 자기자신을 지우기 (0) | 2010.07.07 |
[Delphi] 암호화 (델마당의 박후선님 作) (2) | 2010.07.02 |
[Delphi] IPC - FileMapping [CreateFileMapping, OpenFileMapping, MapViewOfFile] (0) | 2010.07.02 |
[Delphi] 에디트박스 문자열 가져오기 (EM_GETLINE) (0) | 2010.07.01 |