Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   * Platzhalter (https://www.delphipraxis.net/83634-%2A-platzhalter.html)

logo123 5. Jan 2007 09:44


* Platzhalter
 
Hi ich versuche gerade abzufragen of die ausgewählte Datei eine .txt oder .rtf datei ist.

Delphi-Quellcode:
 If Filename = *.rtf then
 begin
  ...
 end
Kann mir jemand helfen?

Tormentor32 5. Jan 2007 09:49

Re: * Platzhalter
 
Schau dir einfach mit
Delphi-Quellcode:
MyString := copy(Filename,length(Filename)-3,4)
die letzten vier Zeichen des Filenames an

edit: ups tippfehler
edit2: na gut, so isses einfacher s.u.

Klaus01 5. Jan 2007 09:49

Re: * Platzhalter
 
Aus der Hilfe:

Zitat:

function ExtractFileExt(const FileName: string): string;
Description

Use ExtractFileExt to obtain the extension from a file name. For example, the following code returns the extension of the file name specified by a variable named MyFileName:

MyFilesExtension := ExtractFileExt(MyFileName);

The resulting string includes the period character that separates the name and extension parts. This string is empty if the given file name has no extension.

Popov 5. Jan 2007 10:13

Re: * Platzhalter
 
Delphi-Quellcode:
  if FileExist(FileName) then
    if ExtractFileExt(LowerCase(FileName)) = '.rtf' then
      ...

marabu 5. Jan 2007 10:27

Re: * Platzhalter
 
Noch eine Alternative:

Delphi-Quellcode:
if FileExist(FileName) then
  if SameText(ExtractFileExt(FileName), '.rtf') then
      ...
Freundliche Grüße vom marabu

shmia 5. Jan 2007 10:28

Re: * Platzhalter
 
Delphi-Quellcode:
  if FileExist(FileName) then
    // zuerst ExtractFileExt, dann LowerCase ist schneller
    if LowerCase(ExtractFileExt(FileName)) = '.rtf' then
      ...


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:55 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz