Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Seek Files

OtmarOtmar Member Posts: 7
Hello :)

I have a problem. I want to make a program that after the user puts a cd or dvd in the unit and press a button called SCAN my program will scan the cd/dvd unit and look for all EXE's files coitaned on the cd and write all them in a text file. How can i do that?

Thanks in advance

Comments

  • zibadianzibadian Member Posts: 6,349
    : Hello :)
    :
    : I have a problem. I want to make a program that after the user puts a cd or dvd in the unit and press a button called SCAN my program will scan the cd/dvd unit and look for all EXE's files coitaned on the cd and write all them in a text file. How can i do that?
    :
    : Thanks in advance
    :
    [code]
    var
    ExeFile: TSearchRec;
    begin
    if FindFirst(Path+'*.exe', faAnyFile, ExeFile) = 0 then repeat
    { do whatever you like here }
    until FindNext(ExeFile) <> 0;
    CloseFile(ExeFile);
    end;
    [/code]
    Here is a piece of code, which searches for all executables in a certain path. I suggest that you read the information on the FindXXX() functions and the TSearchRec type in the help files.
  • OtmarOtmar Member Posts: 7
    Thanks Zibadian

    so, could the path be a string that would contain only the drive where i want to find the EXE files?

    for example

    path:='E:/'

    and then i search using if FindFirst(Path+'*.exe', faAnyFile, ExeFile) = 0 ?

    Thanks!!

  • FractionFraction Member Posts: 20
    : Thanks Zibadian
    :
    : so, could the path be a string that would contain only the drive where i want to find the EXE files?
    :
    : for example
    :
    : path:='E:/'
    :
    : and then i search using if FindFirst(Path+'*.exe', faAnyFile, ExeFile) = 0 ?
    :
    : Thanks!!
    :
    :

    I guess you want to scan your entire CD? then you can do something like this:

    [blue]
    procedure ScanPath(Path: string);
    var
    i: integer;
    SPath: string;
    sr: TSearchRec;
    begin
    SPath := Path;
    if copy(SPath, length(SPath), 1)<>'' then SPath := SPath + ''; // Add '' in the end if needed
    Form1.Label1.Caption := SPath; // Display current path for the user
    Application.ProcessMessages; // and force application to process messages
    i := FindFirst(SPath+'*.*', faAnyFile, sr); // Find all files and directories
    if i=0 then begin // if path is valid
    repeat
    if (sr.Attr and faDirectory)=faDirectory then begin
    if (sr.Name<>'.') and (sr.Name<>'..') then begin // if Directory (not '.' or '..')
    ScanPath(SPath+sr.Name); // Scan this Directory too!!!
    end
    end
    else begin // it's a file
    if lowercase(extractFileExt(sr.Name))='.exe' then begin // if it's a exe-file
    Form1.Memo1.Lines.Add(SPath+sr.Name); // Add it to a TMemo
    end;
    end;
    i := findNext(sr);
    until i>0;
    FindClose(sr); // Don't close SeachRec if FindFirst didn't find anything!
    end;
    end;
    [/blue]

    I use a TLabel (Label1) to inform the user of current dir, and add filenames to a TMemo (Memo1), but it's just an example.

    Then use for example:
    [blue]
    ScanPath('E:');
    [/blue]
  • zibadianzibadian Member Posts: 6,349
    : Thanks Zibadian
    :
    : so, could the path be a string that would contain only the drive where i want to find the EXE files?
    :
    : for example
    :
    : path:='E:/'
    :
    : and then i search using if FindFirst(Path+'*.exe', faAnyFile, ExeFile) = 0 ?
    :
    : Thanks!!
    :
    :
    FindFirst() only shows the first match (see Help). The FindNext() finds the subsequent matches (see Help). The data of each match is listed in the TSearchRec variable (see Help), including its filename.
  • OtmarOtmar Member Posts: 7
    Thanks Zibadian and Fraction.
    I tried here what you told me and both worked.
    Thanks!
Sign In or Register to comment.