function MyExtract( source:string; var fName : string; var cmd : string ) : boolean; var p1, p2 :integer; begin source:= trim(source); p1:= pos('"', source); // recherche 1er car " delete( source, 1, p1 ); // on le vire, si 0, rien à virer if p1>0 then // si 1er était " p2 := pos('"', source) // on rech le 2ème si pas trouvé else p2 := pos(' ', source); // sinon, rech 1er espace après fName fName := copy(source, 1, p2-1); delete( source, 1, p2); cmd := trim(source); result := fileexists( fName ); end;
//------------------------------------------------------------------------------ // Construction de l'objet TRegistry procedure TFRegistry.FormCreate(Sender: TObject); begin {On Crée un objet TRegistry} Regedit := TRegistry.Create; end; //------------------------------------------------------------------------------ // Scan Registre [O.S] procedure TFRegistry.ScanRegistre(Key: String); var {TStringList est la classe, List l'objet} List: TStringList; VarI: Integer; begin {Arret du scan} if StopScan = True then Exit; if Regedit.OpenKeyReadOnly(Key) then try {On appelle le constructeur pour allouer la mémoire} List := TStringList.Create; try {On déterminer les noms de toutes les sous-clés de la clé en cours} Regedit.GetValueNames(List); for VarI := 0 to List.Count - 1 do begin {Appel de procedure : ValideData} ValideData(Key, List.Strings[VarI], ''); {Si la clé List.Strings[I] est du type chaîne} if Regedit.GetDataType(List.Strings[VarI]) in [rdString] then {Appel de procedure : ValideData} ValideData(Key, List.Strings[VarI], Regedit.ReadString(List.Strings[VarI])); end; {On efface la liste} List.Clear; {On déterminer les noms de toutes les sous-clés de la clé en cours} Regedit.GetKeyNames(List); for VarI := 0 to List.Count - 1 do if List.Strings[VarI] <> '' then ScanRegistre(Key + '\' + List.Strings[VarI]); finally {On libérer la mémoire de l'objet} List.Free; end; finally {On ferme la clé} Regedit.CloseKey; end; end; //------------------------------------------------------------------------------ // Bt : Scan procedure TFRegistry.BtScanClick(Sender: TObject); begin TotalP := 0; FLast := 0; try begin {Information} Statut.Panels.Items[2].Text := 'Scan en cour ...'; {Arret du scan = False} StopScan := False; {On efface la liste} Listview.Clear; {On définit la clé [Données liées à la configuration de la machine.]} Regedit.RootKey := HKEY_LOCAL_MACHINE; {Appel de procedure : ScanRegistre} ScanRegistre(''); end; finally {Information} Statut.Panels.Items[2].Text := 'Fin du scan'; end; end; //------------------------------------------------------------------------------ // Validation de la recherche procedure TFRegistry.ValideData(const Key, Value, Root: String); const ChTotal = 'Nombre total : '; ChTotalTrv = 'Total de fichier trouvé : '; var TmpStr: String; begin Inc(TotalP); if TotalP - FLast > 500 then begin FLast := TotalP; Statut.Panels.Items[0].Text := ChTotal + IntToStr(TotalP); Statut.Panels.Items[1].Text := ChTotalTrv + IntToStr(Listview.Items.Count); TmpStr := Key; if Value <> '' then TmpStr := TmpStr + ' {' + Value + '}'; ChKey.Caption := 'HKEY_LOCAL_MACHINE' + TmpStr; Application.ProcessMessages; end; if Root <> 'C:\' then // On élimine 'C:\' if (Pos('C:\', Root) = 1) or (Pos('"C:\', Root) = 1) or (Pos('@C:\', Root) = 1) then |--->> Extraction << ---| end; //------------------------------------------------------------------------------ // Arret du scan procedure TFRegistry.BtStopClick(Sender: TObject); begin StopScan := True; end; //------------------------------------------------------------------------------ // Destruction de l'objet TRegistry procedure TFRegistry.FormDestroy(Sender: TObject); begin {On détruit l'objet TRegistry} Regedit.Free; end;
if (Pos('C:\', Root) = 1) or (Pos('"C:\', Root) = 1) or (Pos('@C:\', Root) = 1) then
les 2ème et 3ème conditions sont inutiles :
car si elles sont vraies, la première l'est aussi (obligatoirement)...
(Pos('C:\', Root) = 1)
(Pos('C:\', Root) <> 0)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionVar I : Integer; root,CopyRoot,ext : String; begin if pos('"C:\',root) = 1 then delete(root,1,1); for I := 0 to Length(Root) do if pos('"',root[I]) > 0 then CopyRoot := Copy(Root,0, I -1); Ext := ExtractFileExt(CopyRoot); if Ext '' then // Si ext '' alor c'est un répertoire begin if not DirectoryExists(Copyroot) then // Si le répertoire n'existe pas on l'affiche end else // Sauf si ext <> '' c'est un fichier if not FileExists (Copyroot) then // Si le fichier n'existe pas on l'affiche end;
function GetFileName(s: string): string; const Unauthorized = ['/', ';', ',', '"', '-']; var PosColon, PosSpace: Integer; begin PosColon := Pos(':', s); PosSpace := Pos(' ', s); Result := Copy(s, PosColon - 1, PosSpace - PosColon + 1); Result := StringReplace(Result, '\\', '\', [rfReplaceAll]); if Result[Length(Result)] in Unauthorized then Delete(Result, Length(Result), 1); end;