File Manipulation With Progress Bar (Move, Copy, Delete, Read, Write, etc)
Basically lets say my application needs to read a file or it needs to copy files around, move them etc... How can I link this with a progress bar to graphically display the "progress" of the operation?
Re: File Manipulation With Progress Bar (Move, Copy, Delete, Read, Write, etc)
Get the file size of the file using the FileLen() command. Then set the max length of the progress bar to the FileLen() file size. As the file is moved or copied adjust the progress bar accordingly.
Re: File Manipulation With Progress Bar (Move, Copy, Delete, Read, Write, etc)
Another option you have to use an Avi file while an operation is going on, that would be much simplier that using progress bar for those tasks...
Or that there is already a method of showing an animation while a file copy is in progress...
Code:
'Module:
Option Explicit
Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Boolean
hNameMappings As Long
lpszProgressTitle As String
End Type
Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Const FO_COPY = &H2
Private Const FOF_ALLOWUNDO = &H40
Public Sub SHCopyFile(ByVal from_file As String, ByVal to_file As String)
Dim sh_op As SHFILEOPSTRUCT
With sh_op
.hWnd = 0
.wFunc = FO_COPY
.pFrom = from_file & vbNullChar & vbNullChar
.pTo = to_file & vbNullChar & vbNullChar
.fFlags = FOF_ALLOWUNDO
End With
SHFileOperation sh_op
End Sub
'Form
Private Sub Command1_Click()
'the following line will copy the file "d:\file.zip" to "d:\temp\file2.zip"
SHCopyFile "c:\dee-u.zip", "d:\dee-u.zip"
End Sub
Re: File Manipulation With Progress Bar (Move, Copy, Delete, Read, Write, etc)