Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy multiple files?

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
If I have several files in a directory with the same name is there a way I can copy all the files at once?

PriorServ.xls
PriorServ.doc

so copy PriorServ.* or do I have to do each one individually?

Thanks! Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
Got it! I put all the files that match the name in a list box on one of my forms and then cycle through the list and copy the files! Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
I would generate a stringlist of file names with something like this (there may be a more elegant way of doing this):

function T_Folder.GetDirFileNames(const ASTR_RootDir : String; var ASTRS_FileNames : TStringList;
ASTR_FileExtension : String) : Boolean;
var
LREC_SearchRec : TSearchRec;
LINT_Erc : Integer;
begin
Result := False;
If not DirectoryExists(ASTR_RootDir) then
Exit;

ASTRS_FileNames.Clear;
ChDir(ASTR_RootDir); //Path to the directory given as parameter
if ASTR_FileExtension = '' then
FindFirst('*.*', faAnyFile, LREC_SearchRec)
else
FindFirst('*.' + ASTR_FileExtension, faAnyFile, LREC_SearchRec);
LINT_Erc := 0;
while LINT_Erc = 0 do //Ignore higher level markers
begin
if ((LREC_SearchRec.Name <> '.' ) and (LREC_SearchRec.Name <> '..')) then
if (LREC_SearchRec.Attr and faDirectory>0) then
else
if LREC_SearchRec.Name <> '' Then
ASTRS_FileNames.Add(LREC_SearchRec.Name);
LINT_Erc := FindNext(LREC_SearchRec);
end;
if ASTRS_FileNames.Count > 0 then
Result := True;
end;

And then look through the filenames for what you're looking for like this:

function T_Folder.GetDirFileNames_ByFilter(const ASTR_RootDir : String; var ASTRS_FileNames : TStringList;
ASTR_SearchText,ASTR_FileExtension : String) : Boolean;
var
i:integer;
begin
result := T_Folder.GetDirFileNames(ASTR_RootDir, ASTRS_FileNames, ASTR_FileExtension);
i := ASTRS_FileNames.Count -1;
While i >= 0 do
begin
if pos(uppercase(ASTR_Searchtext),uppercase(ASTRS_FileNames)) > 0 then
ASTRS_FileNames.Delete(i);
i := i - 1;
end;
end;

And then copy whatever you want to whereever you want by looping through the stringlist.

I guess I did that backwards. Call the T_Folder.GetDirFileNames_ByFilter function and it will call the other one.

Maybe someone out there has a simple function for this.
Brian
&quot;There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group.&quot; - tag line I stole
 
Here's how I did it:
Code:
if not FileExists('C:\Jury\PriorServ.*') then
begin
  if not DirectoryExists('C:\Jury') then
    CreateDir('C:\Jury');
  if FindFirst('O:\JMS\PriorServ.*',faAnyFile,f)=0 then
    repeat
      frmMainMenu.lbFileNames.Items.Add(f.name);
    until FindNext(f)<>0;
    FindClose(f);
  for i := frmMainMenu.lbFileNames.Items.Count - 1 downto 0 do
    CopyFileTo('O:\JMS\' + frmMainMenu.lbFileNames.Items[i],
            'C:\Jury\' + frmMainMenu.lbFileNames.Items[i]);
end;
Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
That is better. Brian
&quot;There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group.&quot; - tag line I stole
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top