Computing Staff
  • 3

Need Help With Timing And Waiting Until Process Ends

  • 3

I am currently trying to make a program in Visual Basic ( not .net or scipting or anything else, just the regular one) in which the following happens:

1: A folder is created
2: Files are copied to that folder
3: Files in that folder undergo a change
4: The files in that folder are then copied to another folder
5: The folder is then deleted

I am basically trying to make a file copied to a new folder where a batch changes its name and then the files are copied to a different folder. Then the folder that was created is destroyed. The problem is that once the system starts to copy the folders, it doesn’t wait until that process is done, it just goes on to the next process of deleting or renaming. I have tried looking at other forums and doing research but I can’t seem to do it correctly. Here is my code:
——————————————————————————————————————–
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
My.Computer.FileSystem.CreateDirectory(“C:\Documents and Settings\Allan\Desktop\Monograms\-23”)
My.Computer.FileSystem.CreateDirectory(“C:\Documents and Settings\Allan\Desktop\Monograms\-3”)
Me.Hide()
If CheckBox1.CheckState = 0 Then
My.Computer.FileSystem.CopyDirectory(“C:\Documents and Settings\Allan\Desktop\Monograms\SAVE”, “C:\Documents and Settings\Allan\Desktop\Monograms\123”, FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing)
My.Computer.FileSystem.CopyDirectory(“C:\Documents and Settings\Allan\Desktop\Monograms\SAVE”, “C:\Documents and Settings\Allan\Desktop\Monograms\-23”, FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing)
My.Computer.FileSystem.CopyDirectory(“C:\Documents and Settings\Allan\Desktop\Monograms\SAVE”, “C:\Documents and Settings\Allan\Desktop\Monograms\-3”, FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing)
End If
If CheckBox1.CheckState = 1 Then
My.Computer.FileSystem.CopyDirectory(“C:\Documents and Settings\Allan\Desktop\Monograms\Save”, “C:\Documents and Settings\Allan\Desktop\Monograms\123”, True)
My.Computer.FileSystem.CopyDirectory(“C:\Documents and Settings\Allan\Desktop\Monograms\Save”, “C:\Documents and Settings\Allan\Desktop\Monograms\-23”, True)
My.Computer.FileSystem.CopyDirectory(“C:\Documents and Settings\Allan\Desktop\Monograms\Save”, “C:\Documents and Settings\Allan\Desktop\Monograms\-3”, True)
End If
System.Diagnostics.Process.Start(“C:\Documents and Settings\Allan\Desktop\Monograms\Properties\Renamer1.bat”)
System.Diagnostics.Process.Start(“C:\Documents and Settings\Allan\Desktop\Monograms\Properties\Renamer2.bat”)
System.Diagnostics.Process.Start(“C:\Documents and Settings\Allan\Desktop\Monograms\Properties\Renamer3.bat”)
My.Computer.FileSystem.CopyDirectory(“C:\Documents and Settings\Allan\Desktop\Monograms\-23”, “C:\Documents and Settings\Allan\Desktop\Monograms\23”)
My.Computer.FileSystem.CopyDirectory(“C:\Documents and Settings\Allan\Desktop\Monograms\-3”, “C:\Documents and Settings\Allan\Desktop\Monograms\3”)
My.Computer.FileSystem.DeleteDirectory(“C:\Documents and Settings\Allan\Desktop\Monograms\-23”, FileIO.DeleteDirectoryOption.DeleteAllContents)
My.Computer.FileSystem.DeleteDirectory(“C:\Documents and Settings\Allan\Desktop\Monograms\-3”, FileIO.DeleteDirectoryOption.DeleteAllContents)
End Sub
———————————————————————————————————————–

So if you study this code carefully, you can see that I want this to go one at a time. The problem with timers is that they automatically have a set time, but they don’t know how long it will take to copy the files. Sometimes the file size will be huge, sometimes the file size will be small. I want the code to do this one at a time and wait until the other process has finished! Please try to adjust and customize the code to my scenerio since when people put a

*.* or other symbols I don’t really know,

I don’t understand how to apply it to my case…

So just for my case please try to adjust the code so I don’t need to worry about certain places I need to fill in.
Sorry about the length of my problem.
Please write back ASAP since I need to get this ground covered already.
Much appreciated,
Allan.

Share

1 Answer

  1. You might have to resort to copying the files (maybe using batch) instead of the copydirectory, to give you more control of the timing. This batch might get the last file to be copied in *.* order:
    for %%a in (source\*) do set lastfile=%%~nxa
    then look for that last file to appear in the target directory before proceeding:
    copy source\*.* dest
    :a
    if not exist dest\%last% goto :a
    which wil hang the batch in a loop until all the files are present.

    • 0