获取剪贴板中所有内容的大小 [英] Get size of everything in clipboard
问题描述
你好
首先,我是这个领域的初学者,我理解基础知识但主要是我的编码与搜索,抓取和组合各种来源的代码有关。 ..更复杂的方式,但这是我的学习曲线:-)
所以,我想获得剪贴板中所有内容的大小(Kb,Mb,Double ......无关紧要)现在我设法用这个代码做了这个:
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:
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
推荐答案
你使用的是错误的工具。您需要获取剪贴板
中的任何对象并使用它。因此,如果剪贴板包含一个文件夹,那么您需要使用该文件夹名称来查找其中的所有文件,使用类似Directory.GetFiles
[ ^ ]。您还需要学习如何创建递归方法,这样您也可以处理任何子文件夹。
You are using the wrong tool. You need to take whatever object is in theClipboard
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 likeDirectory.GetFiles
[^]. You will also need to learn how to create recursive methods, so you can also handle any sub-folders.
这篇关于获取剪贴板中所有内容的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!