|
-
Oct 19th, 2008, 09:30 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] copy flags
ive made a program to backup all my files but the problem i have is when it runs in to a problem with copying the files. i dont know what the problem is ie file corrupt or canceled by user.
so im wantig to add some sort of way or flag for handling this.
the code below works great for me
i have used lngReturn = SHFileOperation(typFO) for returning cancel but cannot figure out how to get error message on file/folder/disk error
i hope someone out there can help me???
Code:
Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Long
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Const FO_DELETE = &H3
Dim Dro
Dim DS As String
Dim DW As String
Dim MM
Dim portable
Dim DD
Dim NewSer As String
Dim prompt As String
Dim DFolder As String
Dim Dpath As String
Dim m, d
Dim XX As String
Dim SHFileOp As SHFILEOPSTRUCT
Dim lngReturn As Long
Public Sub CopyFolder(ByVal Source As String, ByVal Dest As String)
Const FO_COPY As Long = &H2
Const FOF_NOCONFIRMATION As Long = &H10
Const FOF_CREATEPROGRESSDLG As Long = &H0
Const FOF_NOCONFIRMMKDIR As Long = &H200
Const FILE_FLAGS = FOF_NOCONFIRMATION Or FOF_CREATEPROGRESSDLG Or FOF_NOCONFIRMMKDIR
Dim typFO As SHFILEOPSTRUCT
With typFO
.wFunc = FO_COPY
.fFlags = FILE_FLAGS
.pFrom = Source
.pTo = Dest
End With
lngReturn = SHFileOperation(typFO)
End Sub
Private Sub Form_Load()
CopyFolder "c:\windowsggg", "F:\New Folder" 'this will create the problem im trying to sort out
If lngReturn = "1026" Then
MsgBox "problem with file"
End If
If lngReturn = "1223" Then
MsgBox "canceled"
End If
End Sub
programming pc: laptop. running xp pro and vb.net..
media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
2 x video backup: atom 330, 2gb, 18tb harddrive
everything on remote login..
check out my builds http://AtomVaults.yolasite.com
learning vb.net and php + mysql   - got most of the basics now.
I WISH THERE WAS MORE TIME IN THE DAY  
-
Oct 19th, 2008, 10:52 AM
#2
Re: copy flags
Thread moved from CodeBank forum (which is for you to post your code examples, not questions)
-
Oct 19th, 2008, 11:11 AM
#3
-
Oct 19th, 2008, 03:47 PM
#4
Thread Starter
Hyperactive Member
Re: copy flags
thanks Joacim Andersson after looking at your link gave me a bigger picture
this how i did if it if someone else comes across same problem
i put in Const FOF_SILENT As Long = &H4 and added it to
Const FILE_FLAGS = FOF_NOCONFIRMATION Or FOF_CREATEPROGRESSDLG Or FOF_NOCONFIRMMKDIR Or FOF_SILENT
finished code(just cut and past in to a new project
vb Code:
Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Long
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Const FO_DELETE = &H3
Dim Dro
Dim DS As String
Dim DW As String
Dim MM
Dim portable
Dim DD
Dim NewSer As String
Dim prompt As String
Dim DFolder As String
Dim Dpath As String
Dim m, d
Dim XX As String
Dim lngReturn As Long
Dim SHFileOp As SHFILEOPSTRUCT
Public Sub CopyFolder(ByVal Source As String, ByVal Dest As String)
'On Error GoTo errorhanlder
Const FO_COPY As Long = &H2
Const FOF_NOCONFIRMATION As Long = &H10
Const FOF_CREATEPROGRESSDLG As Long = &H0
Const FOF_NOCONFIRMMKDIR As Long = &H200
'new bit to keep silent and just return arror number
Const FOF_SILENT As Long = &H4
'-------------------------------------------------
Const FILE_FLAGS = FOF_NOCONFIRMATION Or FOF_CREATEPROGRESSDLG Or FOF_NOCONFIRMMKDIR Or FOF_SILENT
Dim typFO As SHFILEOPSTRUCT
With typFO
.wFunc = FO_COPY
.fFlags = FILE_FLAGS
.pFrom = Source
.pTo = Dest
End With
lngReturn = SHFileOperation(typFO)
'MsgBox SHFileOperation(fAnyOperationsAborted)
'errorhanlder:
' MsgBox Err.Number
End Sub
Private Sub Form_Load()
CopyFolder "c:\windowsggg", "F:\New Folder'this will creat error for the function
If lngReturn = "1026" Then
MsgBox "problem with file"
End If
If lngReturn = "1223" Then
MsgBox "canceled"
End If
End Sub
Last edited by c_owl; Oct 19th, 2008 at 03:50 PM.
programming pc: laptop. running xp pro and vb.net..
media centre xp pc: dual core 6000,4gb memory, 1tb harddrive
mainserver: server 2008, 8gb memory, amd e-350 dual core, 6tb harddrive and local web host
atomvault 1: server 2008, atom 330 with 4 gb memory, 35TB hardrive space for videos and music..
backup pc : xp, 4gb, atom 330, 10tb harddrive(web, pictures, music, databases)
2 x video backup: atom 330, 2gb, 18tb harddrive
everything on remote login..
check out my builds http://AtomVaults.yolasite.com
learning vb.net and php + mysql   - got most of the basics now.
I WISH THERE WAS MORE TIME IN THE DAY  
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
|