够简单吧,最好有例子
解决方案 »
- 找不到成员。InterFace not supported
- 关于DELPHI ShellAbout调用错误
- 具有挑战性的题目~~~你不想试试吗~~~谁第一个成功额外加分~~~~当然参与者均有分可得
- 纪念Kurt Cobain柯本逝世十年,大家发表下意见
- 怎样改变报表的纸张设置
- 一个很菜的问题!
- 怎么把以*.pas和 *.dcr为后缀名delphi控件注册???????
- 有谁知道海贝二代V2200集成主板的显卡芯片组名称及驱动程序下载地址?
- 程序运行后却不能创建WINDOWS系统类似的任务栏,不知程序哪里出错?
- 在Delphi5中如何调用*.chm帮助文件?
- 何为RAIZE控件
- 菜鸟提问关天BDE的query问题
if not CreateDir('C:\temp') then
raise Exception.Create('Cannot create c:\temp'); //创建目录if FileExists(FileName) then
if MessageDlg('Do you really want to delete ' + ExtractFileName(FileName) + '?'), mtConfirmation, [mbYes, mbNo], 0, mbNo) = IDYes then
DeleteFile(FileName); //删除文件 }//copyfileA('c:\gz\gz.txt','a:\gz.txt',false); //复制文件//ForceDirectories(extractfilepath(application.ExeName)+'bbb');
procedure TForm1.Button1Click(Sender: TObject);
Var
T:TSHFileOpStruct;
P:String;
begin
P:='d:\address';//这里改成你要删除的任意目录名
With T do
Begin
Wnd:=0;
wFunc:=FO_DELETE;
pFrom:=Pchar(P);
pTo:=nil;
fFlags:=FOF_ALLOWUNDO+FOF_NOCONFIRMATION+FOF_NOERRORUI;//标志表明允许恢复,无须确认并不显示出错信息
hNameMappings:=nil;
lpszProgressTitle:='正在删除文件夹';
fAnyOperationsAborted:=False;
End;
SHFileOperation(T);
end;
...
//删除到回收站
procedure TForm1.Button1Click(Sender: TObject);
var
fo: TSHFileOpStruct;
fname: string;
begin
fname := edit1.Text;
with fo do
begin
Wnd := self.Handle;
wFunc := FO_DELETE;
pFrom := Pchar(fname + #0#0);
pTo := nil;
fFlags := FOF_ALLOWUNDO
end; SHFileOperation(fo);
end;
创建目录
function ForceDirectories(const Dir: string): Boolean;
procedure TForm1.Button1Click(Sender: TObject);
begin
ifnot DirectoryExists('c:\temp') then
ifnot CreateDir('C:\temp') then
raise Exception.Create('Cannot create c:\temp');
end;
创建文件
procedure TForm1.Button1Click(Sender: TObject);
var
BackupName: string;
FileHandle: Integer;
StringLen: Integer;
X: Integer;
Y: Integer;
begin
if SaveDialog1.Execute then
begin
if FileExists(SaveDialog1.FileName) then
begin
BackupName := ExtractFileName(SaveDialog1.FileName);
BackupName := ChangeFileExt(BackupName, '.BAK');
if not RenameFile(SaveDialog1.FileName, BackupName) then raise Exception.Create('Unable to create backup file.');
end;
FileHandle := FileCreate(SaveDialog1.FileName);
{ Write out the number of rows and columns in the grid. }
FileWrite(FileHandle,
StringGrid1.ColCount, SizeOf(StringGrid1.ColCount));
FileWrite(FileHandle,
StringGrid1.RowCount, SizeOf(StringGrid1.RowCount));
for X := 0 to StringGrid1.ColCount – 1 do
begin for Y := 0 to StringGrid1.RowCount – 1 do
begin
{ Write out the length of each string, followed by the string itself. }
StringLen := Length(StringGrid1.Cells[X,Y]);
FileWrite(FileHandle, StringLen, SizeOf(StringLen));
FileWrite(FileHandle,
StringGrid1.Cells[X,Y], Length(StringGrid1.Cells[X,Y]);
end;
end;
FileClose(FileHandle);
end;end;删除目录
function RemoveDir(const Dir: string): Boolean;删除文件
function DeleteFile(const FileName: string): Boolean;都是在DELPHI帮忙的
function RemoveDir(const Dir: string): Boolean;删除文件
function DeleteFile(const FileName: string): Boolean;
Type
SECURITY_ATTRIBUTES = Record
nLength: LongInt;
lpSecurityDescriptor: LongInt;
bInheritHandle: Boolean;
End;
var
sDirTest: String;
SecAttrib: SECURITY_ATTRIBUTES;
sPath: PChar;
iCount: Integer;
sTempDir: PChar;
iFlag: Integer;
begin
iFlag := 0;
sTempDir := '';
sPath := PChar(NewDirectory); //等于子程序取得的目录
if (Copy(sPath, StrLen(sPath), 1) <> '\') then //判断,如果最右边的字符不为"\",则加上
begin
sPath := PChar(sPath + '\');
end;
while Pos('\', sPath) > 0 do
begin
iCount := Pos('\', sPath);
sTempDir := PChar(sTempDir + Copy(sPath, 1, iCount));
sPath := sPath + iCount;
if Not DirectoryExists(sTempDir) then
begin
SecAttrib.lpSecurityDescriptor := $00;
SecAttrib.bInheritHandle := false;
SecAttrib.nLength := SizeOf(SecAttrib);
Result := CreateDirectory(sTempDir, @SecAttrib); //建立目录
end;
end;
end;支持多级目录CreateNewDirectory('e:\a\b\c\d\e\f');
ForceDirectories这个函数就能实现你写的功能