0

Does anyone know how this could be achieved.

Lets say our source directory is c:/files/

now inside c:/files/

we have

c:/files/someprogram/folder/anotherfolder/setup.exe
c:/files/someotherprogram/setup.exe

and

c:/files/someVideofolder/Movie.mp4

would it be possible to search the c:/files/ for .exes so that if a directory contains an exe copy the whole directory tree with all its files intact to a new directory c:/CopyFiles/

so its

c:/copyfiles/someprogram/folder/anotherfolder/setup.exe c:/copyfiles/someotherprogram/setup.exe

have been trying this for a while now, with nothing even close to success.

    procedure TForm7.Button4Click(Sender: TObject);
var
   ExePath  : String;
   ExeFiles : Array of String;
 begin


 ExeFiles := TDirectory.GetFiles(Sother,'*.exe',
                   TSearchOption.soAllDirectories,
                   function (const Path: string): Boolean
                   begin
                     Result := true;
                   end);

           {ExePath := TDirectory.GetCurrentDirectory(exefiles);}
           ExePath := TDirectory.GetDirectories(exefiles);
           CopyFilesToPath(exepath, Dother);
Studying.com
  • 109
  • 1
  • 4
  • 10
  • This might give you an idea: http://stackoverflow.com/questions/437728/recursive-file-search-in-net – lintmouse Apr 03 '15 at 14:28
  • Cool thank you will have a look. – Studying.com Apr 03 '15 at 14:54
  • In pseudocode, it's easy: `for dir in basedir { if dir_contains_exe(dir) then copydir(dir, copyfilesdir) }`. So there are three things to do: First, determine how to iterate over the contents of basedir (nonrecursively). Next, figure out how to iterate over the contents of dir (recursively) until you fine a file whose name patches a particular pattern. Finally, figure out how to copy a directory. I suspect you were trying to solve too much at one time. The pseudocode lets us see how to break the problem into smaller pieces. The `dir_contains_exe` function is probably the hardest of the three. – Rob Kennedy Apr 03 '15 at 15:44
  • So, which part of that are you having trouble with? – Rob Kennedy Apr 03 '15 at 15:45
  • Hi Rob I have this so far which copys the exe file to my destination ... but I need it to copy the path `ExeFile := TDirectory.GetFiles(Sourse,'*.exe', TSearchOption.soAllDirectories, function (const Path: string;): Boolean begin Result := true; end); CopyFilesToPath(ExeFile, Detination);` – Studying.com Apr 03 '15 at 15:55
  • Now im trying to add `ExePath := TDirectory.GetDirectories(Exefile); ` then I will just copy the path instead `CopyFilesToPath(ExePath, Destination)` will update and let you know as soon as iv tried it. – Studying.com Apr 03 '15 at 15:59
  • Please put your full trial code in your question to demonstrate what you've tried so far, because SO questions really require it. – Jerry Dodge Apr 03 '15 at 16:03
  • Hi Jerry , code added please see the original post. @JerryDodge – Studying.com Apr 03 '15 at 16:48
  • I see the problem. You think the task has something to do with exe files, so you fetch them, and then wonder what to do with them. But you need to realize that you never need to know *which* exe files are there. You only need to know that *some* exe file is there. Look again at my pseudocode. See how it never actually *uses* the files? It's much easier to fetch the list of directories than to get the list of files and then try to work backward to get the corresponding directories again. – Rob Kennedy Apr 03 '15 at 18:26

0 Answers0