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
Printable View
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
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
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
isn't there any option rather than looping around the files??
just an alternative :D :D :D
regards
And what's wrong with loop structures ?;) There might be other alternatives but can't think of any now . :rolleyes:Quote:
Originally posted by sameer spitfire
isn't there any option rather than looping around the files??
just an alternative :D :D :D
regards
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