How can i get the copy dialog box to appear?
when my program moves a file?
Printable View
How can i get the copy dialog box to appear?
when my program moves a file?
Try this:
Code:Option Explicit
Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Const FOF_NOCONFIRMATION = &H10 ' Don't prompt the user.
Const FOF_NOCONFIRMMKDIR = &H200 ' don't confirm making any needed dirs
Const FO_COPY = &H2
Function jCopy(source As String, target As String) As Boolean
'Copy file(s)/directories from source To destination
'In path of source either file(s) Or folder And path of target As folder
'Out: Boolean indicating success
Dim SHFileOp As SHFILEOPSTRUCT ' structure To pass To the Function
With SHFileOp
.wFunc = FO_COPY
.pFrom = source
.pTo = target
'!!!!!!!make Next Line active To remove confirmation dialog boxes
'.fFlags = FOF_NOCONFIRMATION Or FOF_NOCONFIRMMKDIR
End With
SHFileOperation SHFileOp
jCopy = True
End Function
e.g.
Code:Private Sub Command1_Click()
Call jCopy("c:\tmp", "c:\test\test") ' copy whole folder including subdirectories
Call jCopy("c:\tmp\*.txt", "c:\test") ' copy all text files In a folder
Call jCopy("c:\tmp\american.txt", "c:\test") ' copy a file
End Sub
I have the copy routine.
Can i just get the nice little box thingy?
Thanks james
Don't know quite what you mean, I assume you are talking about the progess bar that appears when you use explorer to copy files?Quote:
Can i just get the nice little box thingy?
If you use the above function to copy your file(s)/directories a progress bar is displayed as the files are moved across. Ideally set the flags on to discard unwanted messages though. Try using with the flags set on and off.
If you insist on using file copy, it will be up to you to create your own progress display.
james:
This what i've got. Thanks for the help! But what when it is copying the files especially if they're big files nothing comes up to tell the user what it's doing!
It can't be on the form because the procedure runs on Form Load! So Status bars etc. can't be seen!
Public Sub movepro() ' this sub moves the files.
Dim copyto As String ' this is a string so it knows where to copy to
On Error Resume Next
Label1.Caption = "STATUS: Copying Files To Destination Folder" ' little status thingy
Dim fso As New FileSystemObject ' win api
Dim AFolder As Folder ' ditto
copyto = dest ' dest is a string declared at startup
If dest = "" Then ' just incase you haven't added anything in
MsgBox "Please Enter A Path", vbExclamation, "Enter Path"
End If
Set AFolder = fso.GetFolder(srce) ' setting which folder to move
fso.CopyFolder AFolder, copyto 'doing the copy
MsgBox "Files Have Been Succesfully Moved", vbInformation, "Moved Folder"
Label1.Caption = "STATUS: Files Moved" 'these 2 tell you if they have gone
Label1.Caption = "STATUS: Deleting Files From Source Folder"
DeleteFiles (srce) ' calls the deletefiles function and deletes the file in srce
Label1.Caption = "STATUS: Files Deleted"
End Sub
Beacon
Have you tried the code I posted yet, it comes with it's own progress bar?
So once you have copied the jCopy function to a bas module you can call it like so:
Public Sub movepro()
Call jCopy(source path, destination path)
end sub
Try it out and tell me how it goes...
yep tried it.
But 1) No box appeared!
2) I don't want the folder just the files underneath it!
don't worry.
I can now show the form and put a progress bar on it!
thanks again jamesm much appreciated!!:)
1) It only appear when large amount of data is being copied.Quote:
yep tried it.
But 1) No box appeared!
2) I don't want the folder just the files underneath it!
2) to copy just the files
jcopy("path\*.*",destination path)
Some would argue that no FSO is another component less to distribute, API direct is also faster.
Glad you got it going anyway.
Thanks i might have to do it this way!
Just wait and see what the users say!
thanks