|
-
Mar 30th, 2006, 01:54 AM
#1
Thread Starter
Lively Member
[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:
start:
Images = "D:\VMware Images\" ' Path were the backup images are
Destination = "D:\Temp\" & temp1 ' Copy to this folder
File1.Path = Images & temp1 ' Copy from this folder
' If old images exist, delete them and make new folder
If Len(Dir$(Destination, vbDirectory)) > 0 Then
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFolder Destination, True ' If exist, delete
Set fso = Nothing
MkDir Destination ' And make new
Else
MkDir Destination ' If not exist, make new
End If
' Define number of files to be copied
b = File1.ListCount - 1
' Progress loop starts here
For a = 0 To b
If Text1.Text = "" Then ' Prevents an empty line at the top
Text1.Text = "Copying " & File1.List(a) & "..."
Else
Text1.Text = Text1.Text & vbCrLf & "Copying " & File1.List(a) & "..." ' Text to be shown on the progress-area
End If
Text1.Refresh ' Show the current file in progress-area that is being copied
FileCopy File1.Path & "\" & File1.List(a), Destination & "\" & File1.List(a) ' Defines the Copy from- and the Copy to paths
Next
' 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
-
Mar 30th, 2006, 01:57 AM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Mar 30th, 2006, 02:18 AM
#3
Thread Starter
Lively Member
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
-
Mar 30th, 2006, 02:25 AM
#4
Frenzied Member
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
-
Mar 30th, 2006, 02:30 AM
#5
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:
Private Const FOF_NOCONFIRMATION As Long = &H10 'THIS IS THE ONE TO ADD FOR NO WARNING OF OVERWRITE
Private Const FOF_NOCONFIRMMKDIR As Long = &H200
Private Const FOF_NOCOPYSECURITYATTRIBS As Long = &H800
Private Const FOF_NOERRORUI As Long = &H400
Private Const FOF_NORECURSION As Long = &H1000
Private Const FOF_RENAMEONCOLLISION As Long = &H8
Private Const FOF_SILENT As Long = &H4
Private Const FOF_WANTNUKEWARNING As Long = &H4000
'...
.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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Mar 30th, 2006, 02:31 AM
#6
Re: App not respondning while copying large files
 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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Mar 30th, 2006, 02:35 AM
#7
Thread Starter
Lively Member
Re: App not respondning while copying large files
 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:
Private Const FOF_NOCONFIRMATION As Long = &H10 'THIS IS THE ONE TO ADD FOR NO WARNING OF OVERWRITE
Private Const FOF_NOCONFIRMMKDIR As Long = &H200
Private Const FOF_NOCOPYSECURITYATTRIBS As Long = &H800
Private Const FOF_NOERRORUI As Long = &H400
Private Const FOF_NORECURSION As Long = &H1000
Private Const FOF_RENAMEONCOLLISION As Long = &H8
Private Const FOF_SILENT As Long = &H4
Private Const FOF_WANTNUKEWARNING As Long = &H4000
'...
.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
-
Mar 30th, 2006, 07:48 AM
#8
Thread Starter
Lively Member
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:
start:
Images = "D:\VMware Images\" ' Path were the backup images are
Destination = "D:\Temp\" & temp1 ' Copy to this folder
File1.Path = Images & temp1 ' Copy from this folder
With SHFileOp
.wFunc = FO_COPY
.pFrom = Images & temp1 'Select a folder and all its subdirectories/files
.pTo = Destination 'You can also rename the file if you want of leave it the same
.fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION Or FOF_NOCONFIRMMKDIR
End With
' If old images exist, delete them and make new folder
If Len(Dir$(Destination, vbDirectory)) > 0 Then
Set fso = CreateObject("Scripting.FileSystemObject") ' If exist, delete
fso.DeleteFolder Destination, True
Set fso = Nothing
MkDir Destination ' And make new
Else
MkDir Destination ' If not exist, make new
End If
' Define number of files to be copied
b = File1.ListCount - 1
' Progress loop starts here
For a = 0 To b
If Text1.Text = "" Then ' Prevents an empty line at the top
Text1.Text = "Copying " & File1.List(a) & "..."
Else
Text1.Text = Text1.Text & vbCrLf & "Copying " & File1.List(a) & "..." ' Text to be shown on the progress-area
End If
Text1.Refresh ' Show the current file in progress-area that is being copied
'perform file operation <<<<< Here's your code
SHFileOperation SHFileOp
Next
' 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
-
Mar 30th, 2006, 08:02 AM
#9
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Mar 30th, 2006, 09:32 AM
#10
Thread Starter
Lively Member
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
-
Mar 30th, 2006, 11:31 AM
#11
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Mar 30th, 2006, 12:23 PM
#12
Thread Starter
Lively Member
Re: App not respondning while copying large files
"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
-
Mar 31st, 2006, 01:31 AM
#13
Thread Starter
Lively Member
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:
' Define number of files to be copied
b = File1.ListCount - 1
' Progress loop starts here
For a = 0 To b
If Text1.Text = "" Then ' Prevents an empty line at the top
Text1.Text = "Copying " & File1.List(a) & "..."
Else
Text1.Text = Text1.Text & vbCrLf & "Copying " & File1.List(a) & "..." ' Text to be shown on the progress-area
End If
Text1.Refresh ' Show the current file in progress-area that is being copied
With SHFileOp
.wFunc = FO_COPY
.pFrom = File1.Path & "\" & File1.List(a) 'Select a folder and all its subdirectories/files
.pTo = Destination & "\" & File1.List(a) 'You can also rename the file if you want of leave it the same
.fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION Or FOF_NOCONFIRMMKDIR Or FOF_MULTIDESTFILES Or FOF_FILESONLY
End With
'perform file operation
SHFileOperation SHFileOp
Next
' 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
-
Mar 31st, 2006, 03:53 AM
#14
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
-
Mar 31st, 2006, 04:03 AM
#15
Thread Starter
Lively Member
Re: App not respondning while copying large files
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|