Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is there a "pattern-matching" operator in Delphi ???

454 views
Skip to first unread message

Hans Olav Stjernholm

unread,
Sep 6, 1999, 3:00:00 AM9/6/99
to
Hello!

I've made programs both for Visual Basic and for Delphi 4. And there are
some functions in
Visual Basic that doesn't exist in Delphi (and vise versa).

The only thing I really long for in Delphi is a possibility to use wildcards
and pattern-matching in
strings.

Remember when you could write "Dir *.exe" in DOS and you'd get all the files
matching that
criteria? Well, this is easy in Visual Basic. You'd just write "IF AnyString
LIKE "*.EXE" THEN ...."

Does anyone have code for this in Delphi, or does it exist but somehow i've
missed it?


I'd apprechiate any help.

Greg Lorriman

unread,
Sep 6, 1999, 3:00:00 AM9/6/99
to
There is bound to be pascal source for regular expression stuff. Search
AltaVista.

Alternatively there is a wildcard routine that comes in the strutils unit in
the RxLib library.


Hans Olav Stjernholm <hans...@hep.no> wrote in message
news:7r03i1$q3...@forums.borland.com...

Delfim

unread,
Sep 6, 1999, 3:00:00 AM9/6/99
to
> Remember when you could write "Dir *.exe" in DOS and you'd get all the
files
> matching that
> criteria? Well, this is easy in Visual Basic. You'd just write "IF
AnyString
> LIKE "*.EXE" THEN ...."
>

Well, there isn't a LIKE keyword in Delphi, but you can use the following:

IF Pos(AnyString, '.EXE') > 0 THEN ...

See Delphi Help for the function POS for more details.

Hope it helps.

Delfim


Greg Lorriman

unread,
Sep 6, 1999, 3:00:00 AM9/6/99
to
Forgot to mention that if you are using findfirst/findnext to gather file
names from a fodler then it will do the pattern matching for you. Ie :

ret:=findfirst('c:\windows\*.exe',searchrec,faany);

Hans Olav Stjernholm <hans...@hep.no> wrote in message
news:7r03i1$q3...@forums.borland.com...
> Hello!
>
> I've made programs both for Visual Basic and for Delphi 4. And there are
> some functions in
> Visual Basic that doesn't exist in Delphi (and vise versa).
>
> The only thing I really long for in Delphi is a possibility to use
wildcards
> and pattern-matching in
> strings.
>

> Remember when you could write "Dir *.exe" in DOS and you'd get all the
files
> matching that
> criteria? Well, this is easy in Visual Basic. You'd just write "IF
AnyString
> LIKE "*.EXE" THEN ...."
>

Ernie Deel

unread,
Sep 6, 1999, 3:00:00 AM9/6/99
to
Hans Olav Stjernholm <hans...@hep.no> wrote in message
news:7r03i1$q3...@forums.borland.com...
> The only thing I really long for in Delphi is a possibility to use wildcards
> and pattern-matching in strings.

HyperString - Freeware at http://efd.home.mindspring.com/tools.htm

--
Ernie Deel, EFD Systems
-------------------------------------------------
Any sufficiently advanced bureaucracy
is indistinguishable from molasses.


D. Yates

unread,
Sep 6, 1999, 3:00:00 AM9/6/99
to
Hans,

Figured I would add this since nobody gave u a full example.

Here is something that I wrote to delete any file based on a file mask.

Notice how u must loop through all the files in the directory looking
for
the ones that match your file mask. So if I wanted to delete all EXE
files
in the directory I would do this:

dkyDeleteFiles('c:\temp', '*.EXE');


{*******************************************************************************
* Delete All Files
*
* Note: This will not delete READ ONLY files or directories.
*******************************************************************************}
function dkyDeleteFiles(FilePath, fileMask : String): Boolean;
var
DeleteFilesSearchRec: TSearchRec;
searchResult : integer;
begin
Result := True;

if NOT DirectoryExists(FilePath) then Exit;

searchResult := FindFirst(FilePath + '\' + fileMask, faAnyFile,
DeleteFilesSearchRec);
try
// Loop through all the file and directory names
while (searchResult = 0) do
begin
// Only Delete files .. this avoids directories
if ( (DeleteFilesSearchRec.Attr AND faDirectory) = 0 ) then
begin
if NOT (DeleteFile(PChar(FilePath + '\' +
DeleteFilesSearchRec.Name))) then
Result := FALSE;
end;

searchResult := FindNext(DeleteFilesSearchRec);
end;

finally
FindClose(DeleteFilesSearchRec);
end;
end;

Hope this helps.
Dave

Hans Olav Stjernholm wrote:
>
> Hello!
>
> I've made programs both for Visual Basic and for Delphi 4. And there are
> some functions in
> Visual Basic that doesn't exist in Delphi (and vise versa).
>

> The only thing I really long for in Delphi is a possibility to use wildcards
> and pattern-matching in
> strings.
>

0 new messages