// simple program for downloading files from phone by extension // © BEZY // Needs at least BMC 2.0 BETA3 program download_it_all_by_ext; // v1.2 var s: string; function IsDir(name: string): boolean; begin result := false; if (length(name) > 2) AND (name[1] = '[') AND (name[length(name)] = ']') then result := true; end; function DownloadItAll(from, dest, ext: string): boolean; var name: string; size, i: integer; List: TStringList; begin result := true; //first read dir contain list := TStringList.create; i := Brew.FindFirst(from, name, size); while i = 0 do begin if size = -1 then list.add('[' + name + ']') // I know this sux, but its just an example else list.add(name); i := Brew.FindNext(name, size); end; Brew.FindClose; // do not forget case i of // there could be an error message BERROR_NO_SUCH_DIR: result := false; BERROR_NO_MORE_ENTRIES: result := true; BERROR_CANCELLED: result := false; BERROR_UNKNOWN: result := true; // sometimes I just get unknown error, you can ignore it else result := false; end; if not result then begin list.free; // NEVER forget to free created instances, there is no garbage collector as in C# or Java exit; end; for i := 0 to list.count-1 do begin name := list.strings[i]; if IsDir(name) then begin name := copy(name, 2, length(name)-2); result := DownLoadItAll(from + name + '/', dest + name + '\', ext) end else if extractFileExt(name) = ext then result := BForm.DownloadFile(from + name, dest + name); if not result then begin list.free; exit; end; end; list.free; result := true; end; // real begining begin s := '.ext'; if inputQuery('Download all files by extension', 'Enter extension (including dot)', s) then if length(s) > 1 then begin DirDlg.title := 'Where do you want to download it?'; BrewDlg.title := 'In which directory do you want to start search?'; if DirDlg.Execute then if BrewDlg.execute then begin BForm.StartBrew; downloadItAll(BrewDlg.DirName, DirDlg.DirName+'\', s); BForm.EndBrew; end; end; end.