Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Findnext Exception.

Posted on 1998-12-27
6
419 Views
Last Modified: 2010-04-04
Hi, mycode is raising an exception and i don't know why. the code searches for .mp3 files
but on the findnext command it raises the exception pleaze help.

the exception is :

Project Mp3IDCompare.exe raised exception class EAccessViolation with message 'Access violation at
address 77F674CB in module 'ntdll.dll'. Read of address 00000027'. Process stopped. Use Step or Run to
continue.

the code is :

dirinfo is of the type Tstringlist.
Searchrec is of the type TSearchrec.
Oldname is of type String.
i is of the type integer.


dirinfo.add('C:\MP3\');
dirinfo.add('C:\MP3\A\');
dirinfo.add('C:\MP3\B\');
dirinfo.add('C:\MP3\C\');

  For I := 0 to DirInfo.Count - 1 do
   begin
    FindFirst(DirInfo.Strings[I]+'*.MP3', faAnyfile, SearchRec);
    while OldName <> SearchRec.Name do
     begin
      OldName:=SearchRec.Name;
      if ((SearchRec.Attr and 16 ) <> 16) {not a directory}
       then begin
             {Some Code}
          end;
      FindNext(SearchRec);
     end;
    FindClose(SearchRec);
   end;


Pleaze help me Thanx,
ruben
0
Comment
Question by:rtieland
  • 3
  • 3
6 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1353310
try doing this,,,,

code := FindFirst(DirInfo.Strings[I]+'*.MP3', faAnyfile, SearchRec);

if not code = 0 then....do the rest...

-Viktor
--Ivanov
0
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1353311
Use this one...

function FindFiles( sDir, sMask: string; rgsFiles: TStrings; bRecursively: Boolean ): Integer;
 var
       SR: TSearchRec;
     begin
       Result := 0;
       if not Assigned( rgsFiles ) then Exit;
       if sDir[ Length( sDir )] <> '\' then AppendStr( sDir, '\' ); // fix dir
       if FindFirst( sDir + sMask, faAnyFile, SR ) = 0 then repeat
         if ( SR.Attr and faDirectory ) <> faDirectory then rgsFiles.Add(
     sDir+SR.Name );
       until FindNext( SR ) <> 0;
       FindClose( SR );
       // recursive part...
       if bRecursively then begin
         if FindFirst( sDir + '*.*', faAnyFile, SR ) = 0 then repeat
           if (( SR.Attr and faDirectory ) = faDirectory ) and ( SR.Name[1] <> '.' )
           then FindFiles( sDir+SR.Name+'\', sMask, rgsFiles, bRecursively );
         until FindNext( SR ) <> 0;
         FindClose( SR );
       end;
       Result := rgsFiles.Count;
     end;

Example call:

FindFiles( 'C:\MP3\', '*.mp3', ListBox1.Items, True );

-Viktor
--Ivanov
0
 
LVL 1

Author Comment

by:rtieland
ID: 1353312
'code' is getting the value '2' from the findfirst command why?

code:=FindFirst(DirInfo.Strings[I]+'*.MP3', faAnyfile, SearchRec);
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 10

Expert Comment

by:viktornet
ID: 1353313
Sorry, the correct one is ...

code := FindFirst(DirInfo.Strings[I]+'*.MP3', faAnyfile, SearchRec);

if code = 0 then //Everything is okay and do your stuff...

It is probably getting 2 because there is no such a directory as C:\MP3 or whatever.... The directory should be a real one that is present... then try including one or two MP3s and see if it works... btw- Why don't you use the function I geve you.. It works fine... try it...

-Viktor
--Ivanov
0
 
LVL 1

Author Comment

by:rtieland
ID: 1353314
The Directory exists and there are mp3 files in it but it still gives '2' (The Directory is a directory on a server and mapped to a drive letter such as r:=\\opcenter\d$ and d$ got a directory MP3 with mp3 files in it).

Does your FindFiles give back the name of the file

please give me a point from where i can work with the file name

thanx,
ruben
0
 
LVL 1

Author Comment

by:rtieland
ID: 1353315
I studied your function and adopted it in my program.
it works Great.

Thanx,
ruben
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question