Results 1 to 4 of 4

Thread: Using wildcards to copy files

  1. #1

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    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:
    1. For Each foundFile As String In My.Computer.FileSystem.GetFiles(Application.StartupPath, Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly, TextBox8.Text)                    
    2. My.Computer.FileSystem.CopyFile(foundFile, IO.Path.Combine(FullPath, foundFile))
    3. Next

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: Using wildcards to copy files

    Still didn't work this is my code
    VB.NET Code:
    1. Dim ThisSession As String = GenerateString()
    2. Dim Foldername As String = "Packed Files"
    3. Dim Fullpath = IO.Path.Combine(FileIO.SpecialDirectories.Temp, Foldername & " - " & ThisSession)
    4. Try
    5.                 Dim SDir As DirectoryInfo = New DirectoryInfo(Application.StartupPath)
    6.                 Dim DestDir As String = Fullpath
    7.                 Dim SDirFiles As FileInfo() = SDir.GetFiles(TextBox8.Text)
    8.                 For Each fileNext In SDirFiles
    9.                     fileNext.CopyTo(DestDir)
    10.                     i += 1
    11.                 Next
    12.             Catch ex As Exception
    13.                 MsgBox("Couldn't pack files from 7", MsgBoxStyle.Critical)
    14.             End Try

  4. #4

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width