Results 1 to 2 of 2

Thread: [RESOLVED] Detect a empty folder and move all files with a specific extension!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2017
    Posts
    96

    Resolved [RESOLVED] Detect a empty folder and move all files with a specific extension!

    Hello everybody!
    glad to talk you again.
    ok i have a slight problem! indeed i want to detect a folder if it is empty.
    then, i would like a piece of coding to move all files in specific format like ".png" and more
    i have this code for detect empty folder but don't work!
    Code:
       If Len(Dir(Application.StartupPath & "\png_PHOTO", vbDirectory)) > 0 Then ' check if empty foder
                    CheckBox5.Checked = True
                Else
                    CheckBox5.Checked = False
                End If
    and this code to move the files: i would like a confirmation! i don't know add more extension.
    Code:
       My.Computer.FileSystem.CopyDirectory(Application.StartupPath & "\YOURCHAR", Application.StartupPath & "\mugen\chars"), "*.png")
    thank you in advance for your help
    Last edited by danzey; Sep 30th, 2020 at 02:19 PM.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: [HELP CODING] Detect a empty folder and move all files with a specific extension!

    You have two requirements:
    1. Is a directory empty?
    2. Move all files with a specific format.


    For your first requirement, you can implement this solution: https://stackoverflow.com/a/954837/1920035
    Converted VB.NET:
    Code:
    Public Function IsDirectoryEmpty(ByVal path As String) As Boolean
        Return Not Directory.EnumerateFileSystemEntries(path).Any()
    End Function
    For your second requirement, you can get all files of a particular type by calling DirectoryInfo.GetFiles and then moving the files by calling File.Move.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Tags for this Thread

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