How to check when Shell32.Folder.CopyHere() is finished

僤鯓⒐⒋嵵緔 提交于 2019-12-30 04:47:31

问题


I need to unzip en zip some files in my application using Shell32. Right now, I use srcFolder.CopyHere(destFolder.Items()) to achieve this. However, my next line of code requires the newly made ZIP-file. But since the CopyHere method is Async, how can I check when it in finished? Right now I use a Thread.Sleep for around 500 ms which is enough for my computer to finish creating the ZIP file, but it's not good code imo.

Any ideas?

More info/code can be provided if necessary.


回答1:


Here is another one for waiting to finish copying

'Wait until the File/Folder has finished writing to zip file...
Do Until Shell.NameSpace(Filename).Items.Count = Shell.NameSpace(Input).Items.Count
    System.Threading.Thread.Sleep(200)
    System.Diagnostics.Debug.Print("Waiting...")
Loop



回答2:


I found it, used something like this:

  srcFolder.CopyHere(destFolder.Items())


            While FileInUse(FILEPATH & "BudgetJaarOverzichtSMB.zip")
                Thread.Sleep(100)
            End While

    Private Function FileInUse(ByVal FilePath As String) As Boolean
        Try
            FileOpen(1, FilePath, OpenMode.Input)
            FileClose(1)
            Return False    ' File not in use
        Catch ex As Exception
            Return True     ' File in use
        End Try
    End Function

Not really perfect but will lose less time than with my first approach.



来源:https://stackoverflow.com/questions/10042801/how-to-check-when-shell32-folder-copyhere-is-finished

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!