Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello

First, I'm beginner in this field and I understand basics but mostly my coding is related with searching, grabbing and combining code from various sources...more complicated way but this is my learning curve :-)
So, I want to get size (Kb, Mb, Double...does not matter) of everything what is in clipboard and for now I managed to do this with this code:


VB
Public Function GetSizeKB(ByVal filename As String) As Double
        Dim info As New IO.FileInfo(filename)
        Return info.Length / 1000
End Function

Public Sub MAX()
        Try
            Dim ArList As New ArrayList
            If Clipboard.ContainsFileDropList() Then
                Dim FileList As System.Collections.Specialized.StringCollection = Clipboard.GetFileDropList()
                For Each FileName As String In FileList
                    ArList.Add(GetSizeKB(FileName))
                Next FileName
                MsgBox(ArList.Cast(Of Double).Sum())
            End If
        Catch ex As Exception
            MsgBox(ex)
        End Try
End Sub


Problem here is that this works only if I copy single files to clipboard. If I copy a Folder that maybe contains another subfolder with files then this does not work.
So how can I achieve this using this code or is there any simpler solution?

Thanks
Best regards
Posted

1 solution

You are using the wrong tool. You need to take whatever object is in the Clipboard and work with that. So if the Clipboard contains a folder then you need to use that folder name to find all the files that are in it, using something like Directory.GetFiles[^]. You will also need to learn how to create recursive methods, so you can also handle any sub-folders.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900