hog Posted August 25, 2005 Posted August 25, 2005 Is there a way to copy all files of a certain type from one folder to another without using loads of code with a loop? example: Filecopy("C:\anyfolder\*.jpg","destinationfolder") Thnx Quote My website
Machaira Posted August 25, 2005 Posted August 25, 2005 Well, it wouldn't be loads of code, but it would be a loop. You're only looking at about a half-dozen lines. Assuming you have a FolderBrowserDialog called fbd: If fbd.ShowDialog = DialogResult.OK Then Dim dirInfo As New DirectoryInfo(fbd.SelectedPath) Dim files() As FileInfo = dirInfo.GetFiles("*.jpg") Dim fInfo As FileInfo Dim newPath As String 'set newpath before this For Each fInfo In files File.Copy(fInfo.Name, newPath & "\\" & fInfo.Name) Next fInfo End If Air-coded so there might be a bug in there, but you should get the idea. :) Quote Here's what I'm up to.
Leaders dynamic_sysop Posted August 29, 2005 Leaders Posted August 29, 2005 you could always use the SHFileOperation API mate http://www.xtremedotnettalk.com/images/smilies/wink.gif you can specify wildcards ( eg: *.jpg , *.bmp , *.whatever ) to allow only certain files to be copied / moved / deleted. here's a quick example... Public Structure SHFILEOPSTRUCT Public hWnd As Integer Public wFunc As Integer Public pFrom As String Public pTo As String Public fFlags As Integer Public fAborted As Integer Public hNameMaps As Integer Public sProgress As String End Structure Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer Private Const FO_COPY As Int32 = &H2 Private Const FO_DELETE As Int32 = &H3 Private Const FO_MOVE As Int32 = &H1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim shStructure As New SHFILEOPSTRUCT '///here i specify the wildcard *.jpg ... Dim currentpath As String = "C:\Documents and Settings\den\My Documents\My Pictures\imgs\*.jpg" '/// images in folder to copy '/// new path to COPY the images to ( jpg only in this case ) Dim newpath As String = "E:\imgs\" '/// new path With shStructure .wFunc = FO_COPY .pFrom = currentpath .pTo = newpath End With SHFileOperation(shStructure) End Sub hope it helps :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.