Private Sub CopyDir(ByVal src As String, ByVal dest As String) Dim di As New DirectoryInfo(src) Dim fsi As FileSystemInfo Dim GetExt As IO.FileInfo Dim FileExt As String For Each fsi In di.GetFileSystemInfos() 'Get source content in a recursive loop, each object is analyzed Try Dim destName As String = Path.Combine(dest, fsi.Name) 'Determine the destination path/name If TypeOf fsi Is FileInfo Then 'Check if object is a file.... GetExt = My.Computer.FileSystem.GetFileInfo(fsi.FullName) 'Get the extension info FileExt = GetExt.Extension 'Assign the extension to a String If CheckExt(FileExt) = True Then 'Call CheckExt function to test if the extension is allowed File.Copy(fsi.FullName, destName, True) 'It is allowed, we copy it End If Else Directory.CreateDirectory(destName) 'If it is not a file it is a directory, so we create it CopyDir(fsi.FullName, destName) 'Do a function loop again for the folder we just created End If Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "File/folder copy loop problem!") Process.GetCurrentProcess.Kill() End Try Next End Sub Public Function CheckExt(ByVal TestExt As String) As Boolean 'Compares a file extension to a list to determine if it's allowed or not Dim AllowedExt As Boolean = True 'Initialise the AllowedExt variable, to true Try If TestExt.ToLower.Contains(".avi") Then 'Start checking the forbidden extensions. .ToLower because Contains() is case sensitive! AllowedExt = False 'Then turn the variable to False End If If TestExt.ToLower.Contains(".divx") Then AllowedExt = False End If If TestExt.ToLower.Contains(".jpeg") Then AllowedExt = False End If If TestExt.ToLower.Contains(".jpg") Then AllowedExt = False End If If TestExt.ToLower.Contains(".mp3") Then AllowedExt = False End If If TestExt.ToLower.Contains(".mpeg") Then AllowedExt = False End If If TestExt.ToLower.Contains(".mpg") Then AllowedExt = False End If If TestExt.ToLower.Contains(".bmp") Then AllowedExt = False End If If TestExt.ToLower.Contains(".gif") Then AllowedExt = False End If If TestExt.ToLower.Contains(".wav") Then AllowedExt = False End If If TestExt.ToLower.Contains(".wmv") Then AllowedExt = False End If If TestExt.ToLower.Contains(".wma") Then AllowedExt = False End If If TestExt.ToLower.Contains(".ogg") Then AllowedExt = False End If If TestExt.ToLower.Contains(".mp4") Then AllowedExt = False End If If TestExt.ToLower.Contains(".m4p") Then AllowedExt = False End If If TestExt.ToLower.Contains(".mp1") Then AllowedExt = False End If If TestExt.ToLower.Contains(".mp2") Then AllowedExt = False End If If TestExt.ToLower.Contains(".png") Then AllowedExt = False End If If TestExt.ToLower.Contains(".mov") Then AllowedExt = False End If If TestExt.ToLower.Contains(".m4v") Then AllowedExt = False End If If TestExt.ToLower.Contains(".m4a") Then AllowedExt = False End If If TestExt.ToLower.Contains(".tif") Then AllowedExt = False End If If TestExt.ToLower.Contains(".tiff") Then AllowedExt = False End If If TestExt.ToLower.Contains(".aac") Then AllowedExt = False End If If TestExt.ToLower.Contains(".aiff") Then AllowedExt = False End If If TestExt.ToLower.Contains(".aif") Then AllowedExt = False End If If TestExt.ToLower.Contains(".aifc") Then AllowedExt = False End If If TestExt.ToLower.Contains(".3gp") Then AllowedExt = False End If If TestExt.ToLower.Contains(".asf") Then AllowedExt = False End If If TestExt.ToLower.Contains(".m1v") Then AllowedExt = False End If If TestExt.ToLower.Contains(".m2v") Then AllowedExt = False End If If TestExt.ToLower.Contains(".mkv") Then AllowedExt = False End If If TestExt.ToLower.Contains(".mpe") Then AllowedExt = False End If Return AllowedExt 'Function returns True if no test was failed, otherwise False. Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "File extension comparison problem!") Process.GetCurrentProcess.Kill() End Try End Function