我想删除整个目录,在网上找到这样一段代码:
procedure TMainForm.DeleteAllFiles(var idFTP: TidFTP; RemoteDir, RootDir:
string);
label
Files;
var
i, DirCount: integer;
Temp: string;
CurrentDir: string;
begin
idFTP.ChangeDir(RemoteDir);
CurrentDir := idFTP.RetrieveCurrentDir;
if Pos(RootDir, idFTP.RetrieveCurrentDir) = 0 then
Exit;
Files:
idFTP.List(nil);
DirCount := idFTP.DirectoryListing.Count;
while DirCount = 0 do begin
Temp := idFTP.RetrieveCurrentDir;
idFTP.ChangeDirUp;
idFTP.RemoveDir(Temp);
idFTP.List(nil);
DirCount := idFTP.DirectoryListing.Count;
for i := 0 to DirCount - 1 do
if idFTP.DirectoryListing[i].FileName = RootDir then
Exit;
end;
for i := 0 to DirCount - 1 do begin
if Pos(RootDir, idFTP.RetrieveCurrentDir) = 0 then
Break;
if idFTP.DirectoryListing[i].ItemType = ditDirectory then begin
DeleteAllFiles(idFTP, idFTP.DirectoryListing[i].FileName, RootDir);
end
else begin
idFTP.Delete(idFTP.DirectoryListing[i].FileName);
goto Files;
end;
end;
end;我是这么调用的:Name := IdFTP1.DirectoryListing.Items[DirectoryListBox.ItemIndex].FileName;
DeleteAllFiles(idFTP1,Name,Name);可是一用这个函数,就停不下来,好像死循环一样,不知道是不是我传递的参数不正确。哪位高人有删除目录的代码,或是帮我找出这段代码的错误吧。
procedure TMainForm.DeleteAllFiles(var idFTP: TidFTP; RemoteDir, RootDir:
string);
label
Files;
var
i, DirCount: integer;
Temp: string;
CurrentDir: string;
begin
idFTP.ChangeDir(RemoteDir);
CurrentDir := idFTP.RetrieveCurrentDir;
if Pos(RootDir, idFTP.RetrieveCurrentDir) = 0 then
Exit;
Files:
idFTP.List(nil);
DirCount := idFTP.DirectoryListing.Count;
while DirCount = 0 do begin
Temp := idFTP.RetrieveCurrentDir;
idFTP.ChangeDirUp;
idFTP.RemoveDir(Temp);
idFTP.List(nil);
DirCount := idFTP.DirectoryListing.Count;
for i := 0 to DirCount - 1 do
if idFTP.DirectoryListing[i].FileName = RootDir then
Exit;
end;
for i := 0 to DirCount - 1 do begin
if Pos(RootDir, idFTP.RetrieveCurrentDir) = 0 then
Break;
if idFTP.DirectoryListing[i].ItemType = ditDirectory then begin
DeleteAllFiles(idFTP, idFTP.DirectoryListing[i].FileName, RootDir);
end
else begin
idFTP.Delete(idFTP.DirectoryListing[i].FileName);
goto Files;
end;
end;
end;我是这么调用的:Name := IdFTP1.DirectoryListing.Items[DirectoryListBox.ItemIndex].FileName;
DeleteAllFiles(idFTP1,Name,Name);可是一用这个函数,就停不下来,好像死循环一样,不知道是不是我传递的参数不正确。哪位高人有删除目录的代码,或是帮我找出这段代码的错误吧。
解决方案 »
- 怎么让imageen自己在指定的位置画一个矩形,例如(100,100,200,200)
- 请问如何实现在软件里加上QQ临时对话功能.
- 为什么要用SQL SERVER?
- 自定义消息
- C/S结构问题?急,望各位大侠指点!!
- 用COM1口做发送端,用COM2口做接受端,怎么样实现数据的传输!!!----哪位老大帮帮忙,急急急!!!!
- 请大家帮忙看一下,药品费用查询SQL语句是否可以这样写?
- GreaterWare 组件发布:瞬间可以改变Ado,bde,dbx等应用为远程系统,安全,快速,原来的代码100%支持,只需要替换一个连接组件就可以了。
- 我从来没学过PB, 现在老板说用PB好, 说学了PB后, 除了VC外, 别的都一看就成, 比DELPHI好多了, 真的吗? 我以前是学DELPHI的. 想开发B/S程序.
- 乱码------------!
- 高分求解!如何在dbgrideh画水平线
- 如何让XMLDocument生成这样的XML文件啊!急!急!急!
procedure TReportform.Delete(path: string);
//删除文件
var
hFindFile:Cardinal;
t,tfile:String;
FindFileData:WIN32_FIND_DATA;
begin
ChDir(path);
hFindFile:=FindFirstFile('*.*',FindFileData);
if hFindFile<>INVALID_HANDLE_VALUE then //搜索到文件
begin
repeat
tfile:=FindFileData.cFileName;
if (tfile='.') or (tfile='..') then
Continue
else
begin
t:=path+'\'+tFile;
DeleteFile(t);
end;
until FindNextFile(hFindFile,FindFileData)=false;
/// FindClose(hFindFile);
end;
end;
你的 DeleteAllFiles(idFTP1,Name,Name); 明显不对 后面一个该改成要删除目录的上级目录的绝对路径 可以通过changedirup 和idFTP.RetrieveCurrentDir查出来
是那个过程中的语句有错误,我还是没找出来,按“zzzzzllllll() ”的说法也不行,时间长了,结下贴吧,谢谢了。
=======================================================================
是不是ftp下有'.','..'這兩個是刪不掉的,所以象死機一樣退不出來呀.----------------------------------
goto Files;從來沒用過goto...不明白.呵呵.
自已做吧,不難的.
type
TFtpDir = record
FileName: string;
ItemType: TIdDirItemType;
end;var
i, DirCount: integer;
ftpDir: array of TFtpDir;begin
if RootDir = '/' then exit;
if Pos(RootDir, RemoteDir) = 0 then exit; idFTP.ChangeDir(RemoteDir);
idFTP.List(nil);
DirCount := idFTP.DirectoryListing.Count;
SetLength(ftpDir, DirCount);
for i := 0 to dirCount - 1 do
begin
ftpDir[i].FileName := idftp.DirectoryListing[i].FileName;
ftpDir[i].ItemType := idftp.DirectoryListing[i].ItemType;
end; for i := 0 to DirCount - 1 do
begin
if (ftpDir[i].ItemType = ditDirectory) and (ftpDir[i].FileName <> '.') and (ftpDir[i].FileName <> '..') then
FTP_DeleteAllFiles(idFTP, RemoteDir+'/'+ftpDir[i].FileName, RootDir)
else if (ftpDir[i].ItemType = ditFile) then
idFTP.Delete(ftpDir[i].FileName);
end; idFTP.ChangeDirUp;
idFTP.RemoveDir(RemoteDir);
end;
重新改了一下,测试过行的