我試圖創建一個函數來檢查是否存在一個文件夾使用Overbyte ICS FTP component.Using從icsftp DIR命令不會在我的筆記顯示什麼登錄。 我有興趣將dir命令的結果解析爲字符串列表以搜索特定的文件夾。ICS FTP - 檢查功能如果FTP服務器上存在的文件夾
目前我使用這樣的indy函數。我怎樣才能與ICS做同樣的事情?
function exista_textul_in_stringlist(const stringul_pe_care_il_caut:string; stringlistul_in_care_efectuez_cautarea:Tstringlist):boolean;
begin
if stringlistul_in_care_efectuez_cautarea.IndexOf(stringul_pe_care_il_caut) = -1 then
begin
result:=false;
//showmessage('Textul "'+text+'" nu exista!');
end
else
begin
result:=true;
//showmessage('Textul "'+text+'" exista la pozitia '+ inttostr(ListBox.Items.IndexOf(text)));
end;
end;
function folder_exists_in_ftp(folder_name_to_search_for,ftp_hostname,ftp_port,ftp_username,ftp_password,ftp_root_folder:string;memo_loguri:Tmemo):boolean;
Var
DirList : TStringList;
ftp:Tidftp;
antifreeze:TidAntifreeze;
var i,k:integer;
begin
dateseparator:='-';
Result := False;
DirList := TStringList.Create;
ftp:=tidftp.Create;
antifreeze:=TidAntifreeze.Create;
try
antifreeze.Active:=true;
ftp.Host:=ftp_hostname;
ftp.Port:=strtoint(ftp_port);
ftp.username:=ftp_username;
ftp.password:=ftp_password;
ftp.Passive:=true;
ftp.Connect;
ftp.ChangeDir(ftp_root_folder);
ftp.List(DirList, folder_name_to_search_for, True);
if DirList.Count > 0 then begin
k := DirList.Count;
DirList.Clear; // DIRLIST will hold folders only
for i := 0 to k - 1 do begin
if (ftp.DirectoryListing.Items[i].FileName <> '.') and (ftp.DirectoryListing.Items[i].FileName <> '..') then begin
if ftp.DirectoryListing.Items[i].ItemType = ditDirectory then begin
DirList.Add(ftp.DirectoryListing.Items[i].FileName);
end;
end;
end;
end;
if exista_textul_in_stringlist(folder_name_to_search_for,DIRLIST) then
begin
Result := True;
memo_loguri.Lines.Add(datetimetostr(now)+' - caut folderul "'+folder_name_to_search_for+'" in directorul ftp "'+ftp_root_folder+'" => EXISTS!');
end
ELSE
begin
result:=false;
memo_loguri.Lines.Add(datetimetostr(now)+' - caut folderul "'+folder_name_to_search_for+'" in directorul ftp "'+ftp_root_folder+'" => NOT exists!');
end;
finally
ftp.Free;
antifreeze.Free;
DirList.Free;
end;
end;
外觀極好的解決方案!我發佈的indy函數花費了大約2秒的時間,並根據ftp文件和文件夾的數量進行解析。你的解決方案是完美的!感謝你們對我的幫助! – user2858981
@ user2858981很高興聽到:) –