在我的应用程序中,我使用以下过程递归扫描任何文件夹和子文件夹,如果文件夹包含文本文件(*.txt)我将文件名添加到我的过程中定义的TStringList:
procedure FileSearch(const PathName: string; var lstFiles: TStringList);
const
FileMask = '*.txt';
var
Rec: TSearchRec;
Path: string;
begin
Path := IncludeTrailingBackslash(PathName);
if FindFirst(Path + FileMask, faAnyFile - faDirectory, Rec) = 0 then
try
repeat
lstFiles.Add(Path + Rec.Name);
until FindNext(Rec) <> 0;
finally
FindClose(Rec);
end;
if FindFirst(Path + '*.*', faDirectory, Rec) = 0 then
try
repeat
if ((Rec.Attr and faDirectory) <> 0) and (Rec.Name <> '.') and
(Rec.Name <> '..') then
FileSearch(Path + Rec.Name, lstFiles);
until FindNext(Rec) <> 0;
finally
FindClose(Rec); …Run Code Online (Sandbox Code Playgroud) 有没有办法在代码部分中浏览和递归复制/移动目录的所有文件和子目录?(PrepareToInstall)
我需要忽略一个特定的目录,但是使用xcopy它会忽略所有目录/default/,例如,我只需要忽略一个特定的目录.
该Files部分在需要时稍后执行.