hi, im having problem with this copy function, im try to copy multiple files at the same time. when i use File.Copy ,it works for one file , if i use it for multiple files it will corrupt the files. The program im try to create will search for specific file like ".*doc" in a given directory and search the subdirectory for the file, then it will put all the file lists in listbox. The problem is that they have different folder so i cannot use the function COPYTO
use FILE.COPY ----------------------------------
this is the code. i have 2 listboxes , (source and destination)
my search function add the file list to listbox1 as source, then combine my destination path with each filename and put it listbox2 for destination
for each src as string in listbox1.selecteditems
for each des as string in listbox2.selecteditems
file.Copy(src,des)
the above code only work when i select one file, for multiple file
it corrupt them
--------------------------------------------------
so for CopyTo,i think it must be the same directory and folder, so if you know how to do it, my source path is in listbox1, and destination path with filename is in listbox2.
so any help pls
Copy multiples filescopy multiple files from the same directory but diffrent folder to a
Page 1 of 1
5 Replies - 10706 Views - Last Post: 04 November 2008 - 02:02 AM
Replies To: Copy multiples files
#2
Re: Copy multiples files
Posted 27 October 2007 - 12:54 PM
kaymaf, is this VB6 or VB.Net, Visual Basic 2005, Visual Basic 2003, Visual Basic 2005 Express Edition are all VB.Net
#3
Re: Copy multiples files
Posted 27 October 2007 - 02:00 PM
If this is VB.Net, unfortunately VB.Net doesn't have the recursive copy functionality that VB6 has, so I created a procedure to do recursive file copying. Remember, this method is in VB.Net, if its VB6 you're using this will not work. I included lots of commenting so you can tell which is going on in the method:
Hope that at least puts you down the path you wish to be on
''' <summary>
''' Method to recursively copy files in a given directory
''' </summary>
''' <param name="source">Directory to copy from</param>
''' <param name="destination">Directory to copy to</param>
''' <param name="recursive">Boolean flag for recursively</param>
''' <param name="replace">Boolean flag for overwriting the current files</param>
''' <remarks></remarks>
Private Sub CopyFiles(ByVal source As String, ByVal destFination As String, ByVal recursive As Boolean, ByVal replace As Boolean)
Dim i As Integer
Dim posSep As Integer
Dim sDir As String
Dim aDirs() As String
Dim sFile As String
Dim aFiles() As String
'Check to see if the source directory contains the trailing
'back slash (\), if not then we need to add it
If Not source.EndsWith(Path.DirectorySeparatorChar.ToString()) Then
source += Path.DirectorySeparatorChar
End If
'Check to see if the destination directory provided contains
'the proper trailing back slash (\), if not then we need to add it
If Not destination.EndsWith(Path.DirectorySeparatorChar.ToString()) Then
destination += Path.DirectorySeparatorChar
End If
'If recursive = True then drill down into the
'directory of the source directory provided
If recursive Then
'We need a list of the directories in the
'parent directory
aDirs = Directory.GetDirectories(source)
'Now loop through all the sub directories
'in the parent directory
For i = 0 To aDirs.GetUpperBound(0)
'Get the integer value of the last
'trailing slash (\)
posSep = aDirs(i).LastIndexOf("\")
'Retrieve the path of source file
sDir = aDirs(i).Substring((posSep + 1), aDirs(i).Length - (posSep + 1))
'Check to see if the destination directory exists,
'if not then we need to create it
If Not Directory.Exists(destination + sDir) Then
Directory.CreateDirectory(destination + sDir)
End If
' Since we are in recursive mode, copy the children also
CopyFiles(aDirs(i), (destination + sDir), recursive, replace)
Next
End If
'Get all the files from the parent directory
aFiles = Directory.GetFiles(source)
'Start our loop, looping through
'all the files in the parent directory
For i = 0 To aFiles.GetUpperBound(0)
'Get the integer value of the
'trailing slash (\) of the current file
posSep = aFiles(i).LastIndexOf("\")
'Get the full path of the current file
sFile = aFiles(i).Substring((posSep + 1), aFiles(i).Length - (posSep + 1))
Try
'Now we need to copy the file
File.Copy(aFiles(i), destination + sFile, replace)
Catch ex As Exception
MessageBox.Show(ex.Message, "Copy Error")
End Try
Next i
End Sub
Hope that at least puts you down the path you wish to be on
#4
Re: Copy multiples files
Posted 05 November 2007 - 03:44 PM
#5
Re: Copy multiples files
Posted 04 November 2008 - 01:10 AM
I like to copy file from remote source to my local destination. I provided the programme below for your reference. But its giving an object error.
Can some body help me
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 21/08/2008 by y120371
'
'
FileSystemObject.CopyFile "http:\\148.185.243.134\ILDstats\results\AUHN01-P-C1_SGE-P-C1_040808.log", "\\gbcwbrkcs002\cwdesktop-profiles\y120371\home\mydocuments\New Folder\"
End Sub
Can some body help me
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 21/08/2008 by y120371
'
'
FileSystemObject.CopyFile "http:\\148.185.243.134\ILDstats\results\AUHN01-P-C1_SGE-P-C1_040808.log", "\\gbcwbrkcs002\cwdesktop-profiles\y120371\home\mydocuments\New Folder\"
End Sub
#6
Re: Copy multiples files
Posted 04 November 2008 - 02:02 AM
this is not the correct method
try to find the code snippet
of use the downloadurl win32 api
try to find the code snippet
of use the downloadurl win32 api
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|