image file count per directoy wise

Arpan Bhunia 1 Reputation point
2022-01-12T17:35:27.577+00:00

164356-capture.png

i want this type of image count by directory wise. and export in csv format. Can anyone help me??.
Please help me if it is possible

Developer technologies | VB
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 60,326 Reputation points
    2022-01-12T18:56:55.623+00:00

    Can you be more specific about what you want? You have shown us a UI for an app that looks custom. Other than a folder name at the top we have no way of knowing what the rest of that stuff is. Are you trying to do this in code? If so then C# can do it rather easily. For example, given a directory name you can find all the files in it using Directory.EnumerateFiles. But if you want to filter by some file type (aka images) then you need to define what an image is to your app (e.g. png and jpg). Also you need to determine if you want current folder only or subfolders as well.

       var files = Directory.EnumerateFiles("myfolderpath", "*.png", SearchOption.TopDirectoryOnly);  
       var count = files.Count();  
    
    0 comments No comments

  2. LesHay 7,141 Reputation points
    2022-01-12T20:13:01.587+00:00

    Hi
    You need to provide more explicit details of what you want.
    Here is an example where you can edit to make 1 csv file for multiple source folders or, split into separate files one for each source folder (etc)

    Option Strict On
    Option Explicit On
    Imports System.Text
    
    Public Class Form1
        Dim path As String = "C:\Users\lesha\Desktop\Test"
        Dim ExportPath As String = "C:\Users\lesha\Desktop\Test2"
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ' make a separate file for each count
            Dim splitup As Boolean = True
    
            ' look in all sub folders too
            Dim d() As String = IO.Directory.GetDirectories(path, "*", IO.SearchOption.AllDirectories)
    
            For Each s As String In d
                Dim t As String = GetF(s)
                TextBox1.AppendText(t)
                If splitup Then
                    Dim p As String = IO.Path.Combine(ExportPath, IO.Path.GetFileName(s) & ".csv")
    
                    IO.File.AppendAllText(p, t)
                Else
                    Dim p As String = IO.Path.Combine(ExportPath, "COMBINED.csv")
                    IO.File.AppendAllText(p, t)
                End If
            Next
        End Sub
        Function GetF(dir As String) As String
    
    
            Dim img() As String = IO.Directory.GetFiles(dir, "*.jpg")
            Dim lst As String = img.Last
            Dim sep As String
            Dim sb As New StringBuilder
    
            ' to include path at start
            sb.Append(dir & ": ")
    
            sb.Append("File count " & img.Count.ToString & ",  ")
            For Each s As String In img
                sep = ", " ' with/without space char
    
                ' remove line for no blank lines
                If s.ToUpper.Contains(lst.ToUpper) Then sep = vbCrLf & vbCrLf
    
                sb.Append(IO.Path.GetFileNameWithoutExtension(s) & sep)
    
            Next
            Return sb.ToString
        End Function
    End Class
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.