Results 1 to 15 of 15

Thread: [RESOLVED] App not respondning while copying large files

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    84

    Resolved [RESOLVED] App not respondning while copying large files

    Hey ,

    I've made an application that copies files from a folder to another, and it shows the progress in a textbox. (That's why I have a FileListBox)

    Well, while copying large files (2-4 GB) the application 'locks itself' and becomes "Not responding". Is there any way how to prevent this? See code below for more details.
    VB Code:
    1. start:
    2.     Images = "D:\VMware Images\"        ' Path were the backup images are
    3.     Destination = "D:\Temp\" & temp1    ' Copy to this folder
    4.     File1.Path = Images & temp1         ' Copy from this folder
    5.    
    6.     ' If old images exist, delete them and make new folder
    7.     If Len(Dir$(Destination, vbDirectory)) > 0 Then
    8.         Set fso = CreateObject("Scripting.FileSystemObject")    
    9.         fso.DeleteFolder Destination, True                 ' If exist, delete
    10.         Set fso = Nothing
    11.         MkDir Destination                                       ' And make new
    12.     Else
    13.         MkDir Destination                                       ' If not exist, make new
    14.     End If
    15.    
    16.     ' Define number of files to be copied
    17.     b = File1.ListCount - 1
    18.    
    19.     ' Progress loop starts here
    20.     For a = 0 To b
    21.         If Text1.Text = "" Then     ' Prevents an empty line at the top
    22.             Text1.Text = "Copying " & File1.List(a) & "..."
    23.         Else
    24.             Text1.Text = Text1.Text & vbCrLf & "Copying " & File1.List(a) & "..."   ' Text to be shown on the progress-area
    25.         End If
    26.         Text1.Refresh   ' Show the current file in progress-area that is being copied
    27.         FileCopy File1.Path & "\" & File1.List(a), Destination & "\" & File1.List(a)    ' Defines the Copy from- and the Copy to paths
    28.     Next
    29.     ' Progress loop ends here
    The temp1 variable is defined earlier.

    Any help is highly appreciated!
    rade

    EDIT: If you didn't understand something, just ask

    EDIT-2: Even though it becomes "Not responding", it works correctly. When it has finished copying, everything is fine again. I just wonder if you can somehow prevent it to become "Not responding"
    Last edited by rade; Mar 30th, 2006 at 01:58 AM.
    "Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
    - Linus Torvalds

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: App not respondning while copying large files

    Try using this method. It uses the Windows file copy/move progress dialog.

    http://www.vbforums.com/showpost.php...45&postcount=2
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    84

    Re: App not respondning while copying large files

    Thank you RobDog888 !! That seems to work great (don't know yet, have to go down to the 1st floor and test with the comp there.(I'm at 5th floor now )

    One further question: Is it possible to force-overwrite the old files? So that this dialog which asks if you're sure you want to overwrite doesn't show up.

    Thanks again
    rade
    "Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
    - Linus Torvalds

  4. #4
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: App not respondning while copying large files

    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: App not respondning while copying large files

    Just add the constant to the flags element to overwrite without prompting.

    Here are more flags that you may want to know about.

    VB Code:
    1. Private Const FOF_NOCONFIRMATION As Long = &H10 'THIS IS THE ONE TO ADD FOR NO WARNING OF OVERWRITE
    2. Private Const FOF_NOCONFIRMMKDIR As Long = &H200
    3. Private Const FOF_NOCOPYSECURITYATTRIBS As Long = &H800
    4. Private Const FOF_NOERRORUI As Long = &H400
    5. Private Const FOF_NORECURSION As Long = &H1000
    6. Private Const FOF_RENAMEONCOLLISION As Long = &H8
    7. Private Const FOF_SILENT As Long = &H4
    8. Private Const FOF_WANTNUKEWARNING As Long = &H4000
    9.  
    10. '...
    11.  
    12. .fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS OR FOF_NOCONFIRMATION
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: App not respondning while copying large files

    Quote Originally Posted by d3gerald
    Have you tested the FileCopy call degerald? I believe it will still peg the cpu during a large copy.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    84

    Re: App not respondning while copying large files

    Quote Originally Posted by RobDog888
    Just add the constant to the flags element to overwrite without prompting.

    Here are more flags that you may want to know about.

    VB Code:
    1. Private Const FOF_NOCONFIRMATION As Long = &H10 'THIS IS THE ONE TO ADD FOR NO WARNING OF OVERWRITE
    2. Private Const FOF_NOCONFIRMMKDIR As Long = &H200
    3. Private Const FOF_NOCOPYSECURITYATTRIBS As Long = &H800
    4. Private Const FOF_NOERRORUI As Long = &H400
    5. Private Const FOF_NORECURSION As Long = &H1000
    6. Private Const FOF_RENAMEONCOLLISION As Long = &H8
    7. Private Const FOF_SILENT As Long = &H4
    8. Private Const FOF_WANTNUKEWARNING As Long = &H4000
    9.  
    10. '...
    11.  
    12. .fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS OR FOF_NOCONFIRMATION
    Yeah thanks, I just read your next post on the thread you linked to Hehe.

    I think it work fine now. Will report when I've tested it.
    Thank you for all this!

    rade
    "Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
    - Linus Torvalds

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    84

    Re: App not respondning while copying large files

    Hi again,

    RobDog888, I tried to do this your way. I'm not sure where to put the code you suggested, but when I put i here, I realized it's inside the loop and it copies the folder as many times as there is files in it. (Because of the Filelistbox loop I have to show the progress in the textbox).
    Where should I put your code, so that I still can show the progress?
    VB Code:
    1. start:
    2.     Images = "D:\VMware Images\"        ' Path were the backup images are
    3.     Destination = "D:\Temp\" & temp1    ' Copy to this folder
    4.     File1.Path = Images & temp1         ' Copy from this folder
    5.     With SHFileOp
    6.         .wFunc = FO_COPY
    7.         .pFrom = Images & temp1 'Select a folder and all its subdirectories/files
    8.         .pTo = Destination 'You can also rename the file if you want of leave it the same
    9.         .fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION Or FOF_NOCONFIRMMKDIR
    10.     End With
    11.    
    12.     ' If old images exist, delete them and make new folder
    13.     If Len(Dir$(Destination, vbDirectory)) > 0 Then
    14.         Set fso = CreateObject("Scripting.FileSystemObject")    ' If exist, delete
    15.         fso.DeleteFolder Destination, True
    16.         Set fso = Nothing
    17.         MkDir Destination                                       ' And make new
    18.     Else
    19.         MkDir Destination                                       ' If not exist, make new
    20.     End If
    21.    
    22.     ' Define number of files to be copied
    23.     b = File1.ListCount - 1
    24.    
    25.     ' Progress loop starts here
    26.     For a = 0 To b
    27.         If Text1.Text = "" Then     ' Prevents an empty line at the top
    28.             Text1.Text = "Copying " & File1.List(a) & "..."
    29.         Else
    30.             Text1.Text = Text1.Text & vbCrLf & "Copying " & File1.List(a) & "..."   ' Text to be shown on the progress-area
    31.         End If
    32.         Text1.Refresh   ' Show the current file in progress-area that is being copied
    33.         'perform file operation  <<<<< Here's your code
    34.         SHFileOperation SHFileOp
    35.     Next
    36.     ' Progress loop ends here
    rade
    "Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
    - Linus Torvalds

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: App not respondning while copying large files

    Try adding the FOF_MULTIDESTFILES const. and I think you pass all the filenames at once.

    Private Const FOF_MULTIDESTFILES As Long = &H1
    Private Const FOF_FILESONLY As Long = &H80

    If your copying all the files in a directory then just specify the folder path and it will do it all.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    84

    Re: App not respondning while copying large files

    Thanks for that. Will post here tomorrow again when I'm at work (have the project there).

    rade
    "Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
    - Linus Torvalds

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: App not respondning while copying large files

    What? You dont bring your work home with you? Not a hard core programmer
    Last edited by RobDog888; Mar 30th, 2006 at 11:35 AM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    84

    Re: App not respondning while copying large files

    Quote Originally Posted by RobDog888
    What? You dont bring your work home with you? Not a hard core programmer
    At home I have enough work with my own personal projects (that is, VB projects)
    "Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
    - Linus Torvalds

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    84

    Re: App not respondning while copying large files

    Yes!
    I got i working perfectly. I just put the same CopyFrom and CopyTo variables in the new code, and that whole bunch of new code in the For loop. Now the current file being copied is shown on the Progress-textbox.
    VB Code:
    1. ' Define number of files to be copied
    2.     b = File1.ListCount - 1
    3.    
    4.     ' Progress loop starts here
    5.     For a = 0 To b
    6.         If Text1.Text = "" Then     ' Prevents an empty line at the top
    7.             Text1.Text = "Copying " & File1.List(a) & "..."
    8.         Else
    9.             Text1.Text = Text1.Text & vbCrLf & "Copying " & File1.List(a) & "..."   ' Text to be shown on the progress-area
    10.         End If
    11.         Text1.Refresh   ' Show the current file in progress-area that is being copied
    12.         With SHFileOp
    13.             .wFunc = FO_COPY
    14.             .pFrom = File1.Path & "\" & File1.List(a) 'Select a folder and all its subdirectories/files
    15.             .pTo = Destination & "\" & File1.List(a) 'You can also rename the file if you want of leave it the same
    16.             .fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION Or FOF_NOCONFIRMMKDIR Or FOF_MULTIDESTFILES Or FOF_FILESONLY
    17.         End With
    18.         'perform file operation
    19.         SHFileOperation SHFileOp
    20.     Next
    21.     ' Progress loop ends here

    Thank you RobDog888 for all your replies!
    rade
    "Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
    - Linus Torvalds

  14. #14
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: App not respondning while copying large files

    Nice work

    You can help us, a bit, by going to the Thread Tools menu above the first post and clicking "Mark Thread Resolved". It's just a thing we do

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    84

    Re: App not respondning while copying large files

    Quote Originally Posted by penagate
    Nice work

    You can help us, a bit, by going to the Thread Tools menu above the first post and clicking "Mark Thread Resolved". It's just a thing we do
    Oh yes, sorry I just forgot
    "Real men don't use backups, they post their stuff on a public ftp server and let the rest of the world make copies."
    - Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width