Форум: "Основная";
Текущий архив: 2002.11.07;
Скачать: [xml.tar.bz2];
ВнизПоиск директорий Найти похожие ветки
← →
Luke (2002-10-24 20:41) [0]Subj
не получается:
пишу
FindFirst("c:\*.*",faDirectory,REc);
Выдаёт все файлы
FindFirst("C:\*.*", fadirectory and (not FaAnyFiles),Rec)
выдаёт все с точнотью да наборот
в качестве маски
c:\* тоже самое
← →
Cobalt (2002-10-24 20:55) [1]var rec:TSearchRec;
i:integer;
begin
if FindFirst("c:\*.*",faDirectory,REc)=0
then while (FindNext(rec)=0) do
begin
//Делаем что-нить...
end;
Работает...
← →
Anatoly Podgoretsky (2002-10-24 20:55) [2]Здемь слово FindFirst настолько ругательно, что даже в ЧаВо есть специальный пример, посмотришь его и приходи с конкретным вопросом. К тому же у тебя вообще нет вопрос только повествование о паршивой жизни
← →
sego (2002-10-24 20:59) [3]Уточни пожалуйста
FindFirst("C:\*.*", fadirectory and (not FaAnyFiles),Rec)
и в результате ты получаешь пустой список?
← →
Luke (2002-10-25 14:19) [4]Прошу прощение, просто я торопился и потому задал вопрос так каряво.
Вот исходный код:
procedure TForm1.Button2Click(Sender: TObject);
var Rec: TSearchRec;
begin
if FindFirst("c:\*.*",FaDirectory,Rec)=0 then
repeat
lbFile.Items.Add(Rec.Name);
until FindNext(rec)<>0;
FindCLose(rec);
end;
lbFile - ListBox, туда помещаются все директории и файлы из C:\
если я впишу вместо "FaDirectory" - " FaDirectory and (not FaAnyFile) " в LbFile появятся все файлы кроме директорий .
Так в чём ошибка?
P.S. Cobalt, по-моему, в вашем примере, будет пропущен первый элемент.
← →
han_malign (2002-10-25 14:47) [5]The Attr parameter specifies the special files to include in addition to all normal files. Choose from these file attribute constants when specifying the Attr parameter:
......................................................
Attributes can be combined by adding their constants or values. For example, to search for read-only and hidden files in addition to normal files, pass (faReadOnly + faHidden) as the Attr parameter.
Так что, надо проверять атрибуты ручками, и заодно, если нужны поддиректории, проверять что не ".." и не ".".
← →
Kudatsky (2002-10-25 14:49) [6]Не проще ли так:
Var
FileListBox1:TFileListBox;
begin
FileListBox1:=TFileListBox.Create(Form1);;
FileListBox1.ParentWindow:=Self.Handle;
FileListBox1.Visible:=false;
FileListBox1.Directory:="C:\Shmrun";
FileListBox1.Mask:="*.txt";
Memo1.Lines.Assign(FileListBox1.Items);
FileListBox1.Free;
← →
panov (2002-10-25 14:49) [7]>han_malign © (25.10.02 14:47)
Проверять "ручками" придется только в корневом каталоге.
Сталкивался с этой проблемой, причем на NT4.0.
В других ОС не проверял, но в NT есть такая особенность.
← →
han_malign (2002-10-25 14:56) [8]
{ File attribute constants }
faReadOnly = $00000001;
faHidden = $00000002;
faSysFile = $00000004;
faVolumeID = $00000008;
faDirectory = $00000010;
faArchive = $00000020;
faAnyFile = $0000003F;
not faAnyFile and faDirectory = not faAnyFile эквивалентно 0
not faAnyFile or faDirectory эквивалентно faDirectory
← →
han_malign (2002-10-25 15:01) [9]2 Panov
sapienti sat:
function FindMatchingFile(var F: TSearchRec): Integer;
var
LocalFileTime: TFileTime;
begin
with F do
begin
while FindData.dwFileAttributes and ExcludeAttr <> 0 do
if not FindNextFile(FindHandle, FindData) then
begin
Result := GetLastError;
Exit;
end;
FileTimeToLocalFileTime(FindData.ftLastWriteTime, LocalFileTime);
FileTimeToDosDateTime(LocalFileTime, LongRec(Time).Hi,
LongRec(Time).Lo);
Size := FindData.nFileSizeLow;
Attr := FindData.dwFileAttributes;
Name := FindData.cFileName;
end;
Result := 0;
end;
function FindFirst(const Path: string; Attr: Integer;
var F: TSearchRec): Integer;
const
faSpecial = faHidden or faSysFile or faVolumeID or faDirectory;
begin
F. ExcludeAttr := not Attr and faSpecial;
F.FindHandle := FindFirstFile(PChar(Path), F.FindData);
if F.FindHandle <> INVALID_HANDLE_VALUE then
begin
Result := FindMatchingFile(F);
if Result <> 0 then FindClose(F);
end else
Result := GetLastError;
end;
function FindNext(var F: TSearchRec): Integer;
begin
if FindNextFile(F.FindHandle, F.FindData) then
Result := FindMatchingFile(F) else
Result := GetLastError;
end;
← →
panov (2002-10-25 16:01) [10]>han_malign © (25.10.02 15:01)
Просто вместо корневого каталога укажи любой и проверь.
Все будет работать.
← →
panov (2002-10-25 16:09) [11]Вот это всегда сработает:
if FindFirst("c:\*.*",faDirectory,Rec)=0 then
repeat
if (Rec.Attr and faDirectory)<>0 then lbFile.Items.Add(Rec.Name);
until FindNext(rec)<>0;
FindCLose(rec);
← →
han_malign (2002-10-25 16:39) [12]ну так я и говорю атрибуты ручками проверять
if (Rec.Attr and faDirectory)<>0 then lbFile.Items.Add(Rec.Name);
З.Ы. Если имелось ввиду ".."и"."то для не корневых каталогах они всегда и на всех системах выдаются.
Страницы: 1 вся ветка
Форум: "Основная";
Текущий архив: 2002.11.07;
Скачать: [xml.tar.bz2];
Память: 0.47 MB
Время: 0.008 c