4

I try to copy multiple files in c# from Folder A to Folder B. I filter the files I want to copy in my Code - after that for example the files 1 , 2 and 5 from Folder A should copy to Folder B. Therefor I want to use the Windows Copy Gui - because I want to see the the copy Progress bar and the Options if any file with the same already name exist.

I´ve found "How to bring up the built-in File Copy dialog?" this article. And I´ve tried to work with the following Options:

Filesystem.CopyFile Filesystem.CopyDirectory

But my Problem is: If I use CopyFile I only can copy ONE File... If I start the CopyFile Statement in loop the Windows Copy GUI will open and close for every file so I cant use the progressbar.

If I use CopyDirectory I only can Copy all files from Folder A to Folder B.

So how can I copy multiple files from Folder A to Folder B with using the WINDOWS COPY GUI ???

Thank you.

  • perform for loop or foreach maybe this is the way – Hitesh Anshani Jul 19 '18 at 11:53
  • The Problem is if i copy the files in a loop or foreach the Filesystem.Copy Funktion will start and open/close the Windows Copy GUI for every file separately – Sunnyboy.94 Jul 19 '18 at 11:57
  • first select files and get all selected File Name or Path then store in array and run loop on array and copy files from folder a to b – Muhammad Usama Alam Jul 19 '18 at 11:57
  • I think it probably would be the best to write your own GUI, which shouldn't be too complicated. – MetaColon Jul 19 '18 at 12:02
  • @MetaColon - I have thought About it, but it must be possible ? I mean if I select some files in Explorer and start copying files the Windows Copy GUI do – Sunnyboy.94 Jul 19 '18 at 12:37
  • This has to be possible, or Windows wouldn't be able to do it. The best I've found when looking into it is summed up in this question: https://stackoverflow.com/questions/7371342/windows-copyfilesdialog-multiple-files-no-folder Looks like you may end up having to implement a decent amount on your own I'm afraid. Sorry don't really have time right now to give an example on how to use it. – Hack Jul 19 '18 at 12:41

1 Answers1

0

It seems you are using VB.Net wrapper over native Windows API and the wrapper limits you. Probably, you can use those (or newer API's) directly and should search into I think you need to use IFileOperation.CopyItems, which accepts array of items as a source, but you'll have to write lots of interop code or find other samples.

dlxeon
  • 1,932
  • 1
  • 11
  • 14
  • Okay sorry for my Question .. but i cant find some Details About "IFileOperation.CopyItems" ? Maybe you can tell me where I can find an example Code how to use ? – Sunnyboy.94 Jul 20 '18 at 05:47
  • @Sunnyboy.94 I found another SO question with link to source code using that interface. https://stackoverflow.com/questions/34418080/c-sharp-ifileoperation-how-to-get-status-and-error-information-for-all-operation Hopefully that would be a good starting point. – dlxeon Jul 20 '18 at 06:07