|
|
|
Existuje soubor nebo složka?
|
13.03.2010
|
Úvod
Pro ověření existence souboru nebo složky můžeme použít následující funkce. Druhá varianta za použití "if not" zní "pokud soubor neexistuje tak...".
Prvky
Button1
Label1
Label2
Kód
procedure TForm1.Button1Click(Sender: TObject);
begin
if FileExists('C:\windows\notepad.exe') then Label1.Caption:='Soubor existuje' else Label1.Caption:='Soubor nebyl nalezen';
if DirectoryExists('C:\windows') then Label2.Caption:='Složka existuje' else Label2.Caption:='Složka nebyla nalezena';
end;
Varianta zápor
procedure TForm1.Button1Click(Sender: TObject);
begin
if not FileExists('C:\windows\notepad.exe') then Label1.Caption:='Soubor nebyl nalezen' else Label1.Caption:='Soubor existuje';
if not DirectoryExists('C:\windows') then Label2.Caption:='Složka nebyla nalezena' else Label2.Caption:='Složka existuje';
end;
|
|
|