Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Общие вопросы Delphi
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 29.10.2006, 10:39   #1
Alar
Александр
Администратор
 
Аватар для Alar
 
Регистрация: 28.10.2006
Сообщений: 17,758
По умолчанию как в каталоге отличить файлы от папок.

перенесено со старого форума. сообщение от Gigan.

Привет!!! Подскажите, по какому признаку можно различить в каталоге папки от файлов и наоборот, чтоб совершать над ними соответствующие действия! Спасибо!

перенесено со старого форума. сообщение от Virtson.

Вот кусок кода из проги, которая работает
в Listview получаем список вида:
d:\folder\subfolder
->file1.xxx
->file2.xxx
...
как видите, процедура рекурсивная ...

procedure TMainF.FindFiles(APath: String);
{***}
var
FSearchRec,
DSearchRec: TSearchRec;
FindResult: integer;
fst1, fst2: AnsiString;
D_Nwas: boolean;
fsz: int64;

function IsDirNotation(ADirName: String): Boolean;
begin
Result := (ADirName = '.') or (ADirName = '..');
end;

begin
APath := GetDirectoryName(APath); // Obtain a valid directory name
FindResult := FindFirst(APath+FFileName,
faAnyFile+faHidden+faSysFile+faRead Only+faArchive, FSearchRec);
D_Nwas:= true;

try
{ Continue to search for the files according to the specified
mask. If found, add the files and their paths to the listbox.}
Current.Caption:= aPath;

while FindResult = 0 do
begin
if D_Nwas then
begin
lbFiles.Items.Add(aPath);
D_Nwas:= false;
end;
fst:= LowerCase(FSearchRec.Name);

if sz_on then
begin
fsz:= FSearchRec.Size;
sum:= sum + fsz;
CurrLine.Caption:= IntToStr(sum);
end;
if dt_on then
Fst2:= DateToStr(FileDateToDateTime(FSearc hRec.Time));

if sz_on then
begin
if dt_on
then lbFiles.Items.Add( Format( '%s'#9'%s'#9'%10.2f'#9'%s', [fchr, fst2, fsz/1024, fst]) )
else lbFiles.Items.Add( Format( '%s'#9'%10.2f'#9'%s', [fchr, fsz/1024, fst]) )
end
else lbFiles.Items.Add( Format( '%s'#9'%s', [fchr, fst]) );
fst:= LowerCase(aPath)+fst;

FindResult := FindNext(FSearchRec);
inc(num);
Number.Caption:= intToStr(num);
if random(10)<4 then Application.ProcessMessages;
if stop then
begin
FindClose(FSearchRec);
exit;
end;
end;

{ Now search the sub-directories of this current directory. Do this
by using FindFirst to loop through each subdirectory, then call
FindFiles (this function) again. This recursive process will
continue until all sub-directories have been searched. }

FindResult := FindFirst(APath+'*.*', faDirectory, DSearchRec);

while FindResult = 0 do
begin
if ((DSearchRec.Attr and faDirectory) = faDirectory) and not
IsDirNotation(DSearchRec.Name) then

FindFiles(APath+DSearchRec.Name); // Recursion here

FindResult := FindNext(DSearchRec);
if random(10)<5 then Application.ProcessMessages;
if stop then
begin
FindClose(FSearchRec);
exit;
end;
end;
finally
FindClose(FSearchRec);
end;
end;

перенесено со старого форума. сообщение от Storm.

Если я правильно понял вопрос, то можно отличить файл от папки функцями DirectoryExists и FileExists.
Alar вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Показ всех имен файлов в каталоге[Delphi] sergey31 Помощь студентам 2 27.07.2008 16:43
как посчитать количество файлов в каталоге? помогите плиз older Общие вопросы Delphi 5 23.05.2008 14:22
организация простенькой парольной защиты .exe файлов в конкретном каталоге abyss Помощь студентам 2 13.11.2007 08:24
два вредных вопроса:про асю и прикриплёные файлы файлы steck Свободное общение 3 17.06.2007 14:53
как отличить формулу от числа Реланиум Microsoft Office Excel 5 21.11.2006 20:14