0

I am trying to create a function that copies a file or a folder and measures the copy time

 public static TimeSpan CopyFileExplorer(string filePath, string fileDestination)
    {

        string command = @"/select, " + filePath;
        System.Diagnostics.Process.Start("explorer.exe", command);
        SendKeys.Send("^(C)");
        command = @"/select, " + fileDestination;
        System.Diagnostics.Process.Start("explorer.exe",command);
        DateTime startCopy = DateTime.Now;
        SendKeys.Send("^(V)"); 

        //need to be catched when explorer finishes the copy
        DateTime endCopy = DateTime.Now;

        return endCopy - startCopy;
    }

I have tried to find when the "copy window" of explorer disappears, but I didn't succeed...

milkana
  • 3
  • 1
  • any reason you do not use `File.Copy(sourceFileName, destFileName)`? – MichaC Oct 05 '13 at 10:25
  • I need to use windows explorer ...and perform the like the user – milkana Oct 05 '13 at 11:05
  • Why? still don't get it, there will be never ever a reason to use something like that and it is very bad practice to send key commands around out of your forms application and open an explorer window... – MichaC Oct 05 '13 at 11:28
  • @Ela One valid argument would be that copying through Explorer allows copying to locations that aren't simple directories (ZIP files, FTP servers, etc.). That still wouldn't require sending keys to other processes, but it would be a reason to not use `File.Copy`. (I think [`IFileOperation`](http://msdn.microsoft.com/en-us/library/windows/desktop/bb775771%28v=vs.85%29.aspx) would be the right way to go, but I'm not entirely sure.) –  Oct 05 '13 at 11:37
  • I know that this is an awful way... and mo one will copy a file in such a way... My goal is to perform the copy of the files like a regular user using the windows explorer and measure the time it takes – milkana Oct 05 '13 at 11:38
  • @milkana maybe read about other ways to do it here: http://stackoverflow.com/questions/8647447/send-folder-rename-command-to-windows-explorer and here http://stackoverflow.com/questions/6400419/c-sharp-send-commands – MichaC Oct 05 '13 at 11:42

1 Answers1

0

Although I don't get the reason why you would ever do some awful stuff like that

you should try SendKeys.SendWait("");

Regarding the solution to send ctrl+c, ctrl+v to the explorer window, here are some other threads about how to use the explorer:

Send Folder Rename Command to Windows Explorer

C# Send Commands

Community
  • 1
  • 1
MichaC
  • 13,104
  • 2
  • 44
  • 56