Using wildcards to copy files
Ok i want to copy all the files in a directory with an extension e.g .exe or maybe all them files *.* how do i do this?
I searched on google and found this on MSDN But it doesn't work when i type *. or *.* or *.exe into the textbox and there is files in that folder
VB.NET Code:
For Each foundFile As String In My.Computer.FileSystem.GetFiles(Application.StartupPath, Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, TextBox8.Text)
My.Computer.FileSystem.CopyFile(foundFile, IO.Path.Combine(FullPath, foundFile))
Next
Re: Using wildcards to copy files
Try this
Code:
Dim SDir As DirectoryInfo = New DirectoryInfo("c:\SourceDir")
Dim DestDir as string = "c:\MyDest"
Dim SDirFiles As FileInfo() = SDir.GetFiles("*.Exe")
For Each fileNext In SDirFiles
fileNext.CopyTo (DestDir)
Next
Re: Using wildcards to copy files
Still didn't work this is my code
VB.NET Code:
Dim ThisSession As String = GenerateString()
Dim Foldername As String = "Packed Files"
Dim Fullpath = IO.Path.Combine(FileIO.SpecialDirectories.Temp, Foldername & " - " & ThisSession)
Try
Dim SDir As DirectoryInfo = New DirectoryInfo(Application.StartupPath)
Dim DestDir As String = Fullpath
Dim SDirFiles As FileInfo() = SDir.GetFiles(TextBox8.Text)
For Each fileNext In SDirFiles
fileNext.CopyTo(DestDir)
i += 1
Next
Catch ex As Exception
MsgBox("Couldn't pack files from 7", MsgBoxStyle.Critical)
End Try
Re: Using wildcards to copy files
guys can someone please have a second look at my code, you know when you look at your own code sometimes you cant spot mistakes. Thankyou.