|
-
Nov 9th, 2011, 03:05 AM
#1
Thread Starter
Junior Member
Help Please simple copy files
hey im making a program to copy files from point a to point b this will contain a list of jar files i would like to use cmd but control it with my program i have an idea of wat to do but basicly i wanna move directorys and jar files with different names im using this as a back up program its not that many files in cmd it takes like 1 min but i wanna release this to public with out people recoding it and sending viruses to every one if you get my drift thats y i wanna use vb instead of a bat file
-
Nov 9th, 2011, 03:50 AM
#2
Thread Starter
Junior Member
Re: Help Please simple copy files
-
Nov 9th, 2011, 05:08 AM
#3
Re: Help Please simple copy files
you could use vb filecopy
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 9th, 2011, 10:17 AM
#4
Re: Help Please simple copy files
Keep in mind that if the file is in use when you attempt to copy it the copy will error out so make sure you build in the necessary error trapping.
-
Nov 9th, 2011, 08:09 PM
#5
Thread Starter
Junior Member
Re: Help Please simple copy files
is there another way to copy files if so can you supply code
-
Nov 9th, 2011, 11:31 PM
#6
Re: Help Please simple copy files
As Westconn1 said you can use filecopy for a simple copy method:
vb Code:
Private Sub Command1_Click() FileCopy "c:\.rnd", "g:\.rnd" End Sub
or a slightly more advanced method which copies the entire contents of a folder:
vb Code:
Option Explicit Private source As String, destination As String Private Sub Command1_Click() source ="c:\New Folder\" destination = "d:\New Folder\" VBCopyFolder(source, destination) End Sub
Place this in a module:
vb Code:
Private Type SHFILEOPSTRUCT hWnd As Long wFunc As Long pFrom As String pTo As String fFlags As Integer fAnyOperationsAborted As Long hNameMappings As Long lpszProgressTitle As Long ' only used if FOF_SIMPLEPROGRESS, sets dialog title End Type Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long ' Available Operations Private Const FO_COPY = &H2 ' Copy File/Folder Private Const FO_DELETE = &H3 ' Delete File/Folder Private Const FO_MOVE = &H1 ' Move File/Folder Private Const FO_RENAME = &H4 ' Rename File/Folder ' Flags Private Const FOF_ALLOWUNDO = &H40 ' Allow to undo rename, delete ie sends to recycle bin Private Const FOF_FILESONLY = &H80 ' Only allow files Private Const FOF_NOCONFIRMATION = &H10 ' No File Delete or Overwrite Confirmation Dialog Private Const FOF_SILENT = &H4 ' No copy/move dialog Private Const FOF_SIMPLEPROGRESS = &H100 ' Does not display file names Public Sub VBCopyFolder(ByRef strSource As String, ByRef strTarget As String) Dim op As SHFILEOPSTRUCT With op .wFunc = FO_COPY ' Set function .pTo = strTarget ' Set new path .pFrom = strSource ' Set current path .fFlags = FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION And FOF_FILESONLY End With ' Perform operation SHFileOperation op End Sub
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Nov 10th, 2011, 12:36 AM
#7
Thread Starter
Junior Member
Re: Help Please simple copy files
night walker you helped me alot ill see wat i can do and see if this does wat i would like it to do until then i will let you know
-
Nov 10th, 2011, 01:48 AM
#8
Thread Starter
Junior Member
Re: Help Please simple copy files
the code is erroring on line 34 in the module can you check over the code and make sure its correct please and thank you im using the vbcopyfolder btw just to let you know
-
Nov 10th, 2011, 01:57 AM
#9
Re: Help Please simple copy files
 Originally Posted by Jeremy
the code is erroring on line 34 in the module can you check over the code and make sure its correct please and thank you im using the vbcopyfolder btw just to let you know
What is the error you receive on that line?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Nov 10th, 2011, 02:39 AM
#10
Thread Starter
Junior Member
Re: Help Please simple copy files
Compile Error:
Varible Required - Can't Assdign to This Expression
its also highlighting op
hopefully this helps
-
Nov 10th, 2011, 04:08 AM
#11
Re: Help Please simple copy files
Can you post the exact code you are using? I created a program using the exact code in post #6 and it works for me.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Nov 10th, 2011, 04:16 AM
#12
Re: Help Please simple copy files
have you change the source and destination folders to folders that exist on your computer?
(lines 4 and 5)
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 10th, 2011, 08:29 AM
#13
Re: Help Please simple copy files
You need to remove the brackets on this line as well
Code:
VBCopyFolder(source, destination)
You may also need to remove the trailing "\" on the source folder, or add *.* after it.
EDIT: and the fflags settings should be
Code:
.fFlags = FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION Or FOF_FILESONLY
Also you should check the return from the function SHFileoperation ( 0 = success) and also the fAnyOperationsAborted member of the SHFILEOPSTRUCT structure (0 = no operations aborted)
Code:
' Perform operation
If SHFileOperation(op) = 0 Then
If op.fAnyOperationsAborted = 0 Then
MsgBox "Copy Complete"
Else
MsgBox "Copy Incomplete"
End If
Else
MsgBox "Copy Failed"
End If
End Sub
Last edited by Doogle; Nov 10th, 2011 at 08:49 AM.
-
Nov 10th, 2011, 12:33 PM
#14
Thread Starter
Junior Member
Re: Help Please simple copy files
is there a way that i can force a overwrite when im coping the folder :/
-
Nov 10th, 2011, 04:43 PM
#15
Re: Help Please simple copy files
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Nov 10th, 2011, 05:17 PM
#16
Thread Starter
Junior Member
Re: Help Please simple copy files
ok i get that and everything but how would i enable that in my code i dont really understand
-
Nov 10th, 2011, 05:39 PM
#17
Re: Help Please simple copy files
vb Code:
Dim op As SHFILEOPSTRUCT With op .wFunc = FO_COPY ' Set function .pTo = strTarget ' Set new path .pFrom = strSource ' Set current path .fFlags = FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION Or FOF_FILESONLY AND FOF_SILENT End With
See the ".fFlags" line.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Nov 10th, 2011, 07:43 PM
#18
Re: Help Please simple copy files
I think that Nightwalker meant
Code:
.fFlags = FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION Or FOF_FILESONLY Or FOF_SILENT
-
Nov 10th, 2011, 07:56 PM
#19
Re: Help Please simple copy files
 Originally Posted by Doogle
I think that Nightwalker meant
Code:
.fFlags = FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION Or FOF_FILESONLY Or FOF_SILENT
Well, if it can't handle two or more things at once then yes, that is correct.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Nov 11th, 2011, 01:53 AM
#20
Re: Help Please simple copy files
I was referring to the use of 'Or' rather than 'And' to include a flag.
-
Nov 11th, 2011, 01:57 AM
#21
Re: Help Please simple copy files
 Originally Posted by Doogle
I was referring to the use of 'Or' rather than 'And' to include a flag.
Yeah, I know but it would depend on what the user wants 'and' would be inclusive while 'or' one or the other.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Nov 11th, 2011, 02:12 AM
#22
Re: Help Please simple copy files
 Originally Posted by Nightwalker83
Yeah, I know but it would depend on what the user wants 'and' would be inclusive while 'or' one or the other.
Not quite.
Code:
FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION Or FOF_FILESONLY And FOF_SILENT
equates to
&H100 Or &H80 Or &H10 And &H4 = &H190 ie the &H4 bit is off
whereas
Code:
FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION Or FOF_FILESONLY Or FOF_SILENT
equates to
&h100 Or &H80 Or &H10 Or &H4 = &H194 ie the &H4 bit is on.
Remember we're dealing with logical operators, to 'add' to the flags value you have to use 'Or' not 'And'.
Last edited by Doogle; Nov 11th, 2011 at 02:24 AM.
Reason: Correected additions
-
Nov 11th, 2011, 02:30 AM
#23
Thread Starter
Junior Member
Re: Help Please simple copy files
k now im confused what part of the module would i edit i am using the code that doogle gave me i just dont understand where to put the silent thing
-
Nov 11th, 2011, 02:38 AM
#24
Re: Help Please simple copy files
 Originally Posted by Jeremy
k now im confused what part of the module would i edit i am using the code that doogle gave me i just dont understand where to put the silent thing
Exactly where it is in post #6 except where it says 'And' in post #6 put 'Or' like:
vb Code:
FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION Or FOF_FILESONLY Or FOF_SILENT
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Nov 11th, 2011, 02:29 PM
#25
Thread Starter
Junior Member
Re: Help Please simple copy files
alright heres another question how would i access the appdata
blah = appdata\test
thats wat i wanna do but i really dont know how can any one help me please
-
Nov 11th, 2011, 05:42 PM
#26
Re: Help Please simple copy files
You can use this code to retrieve the location of the appdata folder as well as others.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Nov 23rd, 2011, 09:15 AM
#27
Junior Member
Re: Help Please simple copy files
First not trying to highjack the thread but I have a problem with this code and I cant figure out why its doing it. For some reason when I use the code it copies the files/Folders "C:\test\whatever" to "F:\test\whatever" fine but then tries to copy and overwrite them again. I have tried everything I can think of to make this not happen anyone know why its happening?
-
Nov 23rd, 2011, 04:53 PM
#28
Re: Help Please simple copy files
 Originally Posted by jstinnett
First not trying to highjack the thread but I have a problem with this code and I cant figure out why its doing it. For some reason when I use the code it copies the files/Folders "C:\test\whatever" to "F:\test\whatever" fine but then tries to copy and overwrite them again. I have tried everything I can think of to make this not happen anyone know why its happening?
Could please post the exact could you are using so we can see if there anything that needs changing in you code. Thanks!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Nov 23rd, 2011, 06:18 PM
#29
Junior Member
Re: Help Please simple copy files
form
Code:
Option Explicit
Private source As String, destination As String
Private Sub Command1_Click()
source = "C:\squad"
destination = Text1.Text
VBCopyFolder source, destination
End Sub
Private Sub Command2_Click()
source = Text1.Text
destination = "C:\"
VBCopyFolder source, destination
End Sub
Private Sub Command3_Click()
Timer2.Enabled = True
Timer2.Enabled = False
End Sub
Private Sub Command4_Click()
'Text3.Text = FileDateTime("C:\test.txt")
End Sub
Private Sub Form_Load()
End Sub
Private Sub Timer1_Timer()
Text1.Text = Drive1.Drive + Text2.Text
End Sub
Private Sub Timer2_Timer()
Drive1.Refresh
End Sub
Modules
Code:
Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As Long ' only used if FOF_SIMPLEPROGRESS, sets dialog title
End Type
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
' Available Operations
Private Const FO_COPY = &H2 ' Copy File/Folder
Private Const FO_DELETE = &H3 ' Delete File/Folder
Private Const FO_MOVE = &H1 ' Move File/Folder
Private Const FO_RENAME = &H4 ' Rename File/Folder
' Flags
Private Const FOF_ALLOWUNDO = &H40 ' Allow to undo rename, delete ie sends to recycle bin
Private Const FOF_FILESONLY = &H80 ' Only allow files
Private Const FOF_NOCONFIRMATION = &H10 ' No File Delete or Overwrite Confirmation Dialog
Private Const FOF_SILENT = &H4 ' No copy/move dialog
Private Const FOF_SIMPLEPROGRESS = &H100 ' Does not display file names
Public Sub VBCopyFolder(ByRef strSource As String, ByRef strTarget As String)
Dim op As SHFILEOPSTRUCT
With op
.wFunc = FO_COPY ' Set function
.pTo = strTarget ' Set new path
.pFrom = strSource ' Set current path
.fFlags = FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION Or FOF_FILESONLY
End With
' Perform operation
SHFileOperation op
If SHFileOperation(op) = 0 Then
If op.fAnyOperationsAborted = 0 Then
MsgBox "Copy Complete"
Else
MsgBox "Copy Incomplete"
End If
Else
MsgBox "Copy Failed"
End If
End Sub
-
Nov 23rd, 2011, 06:35 PM
#30
Re: Help Please simple copy files
You're performing the copy twice
Code:
SHFileOperation op
If SHFileOperation(op) = 0 Then
You just need
Code:
If SHFileOperation(op) = 0 Then
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
|