|
-
Mar 16th, 2004, 02:14 AM
#1
Thread Starter
Fanatic Member
Copy multiple files
VB Code:
FileCopy(strSource, strDestination)
This is the way i know to copy one file from one directory to other. But how about copying multiple files? Like copying *.txt from Folder1 to Folder2.
pls guide
regards
-
Mar 16th, 2004, 03:11 AM
#2
Sleep mode
Try this , I didn't test it though .
VB Code:
Try
Dim files() As String = Directory.GetFiles("c:\folder", "*.txt")
For Each fil As String In files
File.Copy(fil, destnationFolder)
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
-
Mar 16th, 2004, 03:24 AM
#3
Sleep mode
This one tested and working :
VB Code:
Private Sub CopyFiles()
Const desntationfolder As String = "c:\folder2"
Try
Dim files() As String = Directory.GetFiles("c:\folder1", "*.txt")
For Each fil As String In files
File.Copy(fil, desntationfolder + "\" + Path.GetFileName(fil))
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
-
Mar 22nd, 2004, 01:27 AM
#4
Lively Member
isn't there any option rather than looping around the files??
just an alternative
regards
with Regards
sameer Mulgaonkar

-
Mar 22nd, 2004, 04:22 AM
#5
-
Nov 12th, 2009, 02:35 PM
#6
Member
Re: Copy multiple files
Hello guys, I have 2 folders. A source and a destination folder.
Destination folder is a folder in my "Program files", and I want to make an application to look for new files from source folder, and copy them to destination folder.
In source folder, it is possible to find only files, or files and folders and subfolders.
My problem is that I want to copy only files, not folders.
I want my application to navigate to each subfolder copy files to the same subfolder of destination folder in "Program files"
My problem is that I don't know how to take the destination
folder & subfolder & file.name in a string.
Thanks for any help
Code:
Private Sub CopyFilesDir(ByVal sDir As DirectoryInfo, ByVal dDir As DirectoryInfo)
Dim dirs() As DirectoryInfo = sDir.GetDirectories
Dim dir As DirectoryInfo
Dim sf1 As String
For Each dir In dirs
For Each f As FileInfo In dir.GetFiles
sf1 = dir.FullName & "\" & f.Name
Copyfiles(sf1, destination, true)
Next
Next
End Sub
EDIT: I did it with split string.
Code:
Private Sub SplitPath(ByVal s As String)
LineOfText = s
aryTextFile = LineOfText.Split("\")
Dim i As Integer
For i = 0 To UBound(aryTextFile)
If i >= 5 Then
sPath &= aryTextFile(i) & "\"
Else
sPath = ""
End If
Next i
Last edited by manin; Nov 13th, 2009 at 05:30 PM.
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
|