我需要比較兩個不同的串列,其中包含需要從路徑 ( chosenDirectoryfrom FOpenDialog.FileName)復制到本地存盤庫 ( PathLocalRepo = ExtractFilePath(Application.ExeName) LOCAL_REPOSITORY_01)的檔案夾名稱。
問題是我需要檢查檔案夾名稱是否已經存在于我的本地存盤庫中,如果存在,那么我需要轉義我的回圈并繼續下一個值。
這是我的代碼:
for N := 0 to ListFoldersImported.Count-1 do
begin
for Y := 0 to ListFoldersLocalRepository.Count-1 do
begin
if MatchStr(ExtractFileName(ListFoldersImported[N]), ExtractFileName(ListFoldersLocalRepository[Y])) = True then
begin
FlagFound := True;
Break;
end else
begin
FlagFound := False;
ListOfFoldersThatNeedsToBeCopied.Add(ListFoldersImported[N]);
end;
end;
if FlagFound = False then
TDirectory.Copy(chosenDirectory,PathLocalRepo)
end;
如果此代碼找到第一次出現,它不會停止我的回圈,并且它不會繼續將 [Y] 與下一個 [N] 值進行比較。
uj5u.com熱心網友回復:
也許你需要下一個邏輯:
for N:= 0 to ListFoldersImported.Count-1 do
begin
FlagFound := False;
for Y:= 0 to ListFoldersLocalRepository.Count-1 do
begin
if MatchStr(ExtractFileName(ListFoldersImported[N]),ExtractFileName(ListFoldersLocalRepository[Y])) = True then
begin
FlagFound := True;
Break;
end;
end;
if not FlagFound then
begin
ListOfFoldersThatNeedsToBeCopied.Add(ListFoldersImported[N]);
TDirectory.Copy(chosenDirectory,PathLocalRepo);
end;
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/371177.html
