vb.net的fso net vb
vb.net中,不使用FSO方法,怎么快速的得到文件夹的大小?
窗体上添加一个按钮,代码如下:
网站的建设创新互联公司专注网站定制,经验丰富,不做模板,主营网站定制开发.小程序定制开发,H5页面制作!给你焕然一新的设计体验!已为生料搅拌车等企业提供专业服务。
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Text = "稍等!"
Button1.Enabled = False
Dim MyFolder As String = "C:\Windows"
Dim MyDir As New System.IO.DirectoryInfo(MyFolder)
Dim MyInfo As String = MyFolder + "文件夹的大小是:" + CalculateDirectorySize(MyDir, True).ToString() + "字节。"
MessageBox.Show(MyInfo, "信息提示", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Button1.Text = "开始"
Button1.Enabled = True
End Sub
Public Shared Function CalculateDirectorySize(ByVal MyDirectory As System.IO.DirectoryInfo, ByVal IsSubDirectories As Boolean) As Long
Dim MySize As Long = 0
'检查包含的所有文件
Dim MyFiles() As System.IO.FileInfo = MyDirectory.GetFiles()
For Each MyFile As System.IO.FileInfo In MyFiles
MySize += MyFile.Length
Next
'检查包含的所有子文件夹
If (IsSubDirectories) Then
Dim MyDirs() As System.IO.DirectoryInfo = MyDirectory.GetDirectories()
For Each MyDir As System.IO.DirectoryInfo In MyDirs
MySize += CalculateDirectorySize(MyDir, True)
Next
End If
Return MySize
End Function
End Class
VB.NET 创建文件夹
用Directory.CreateDirectory即可创建文件夹:
' 建立目录
If Not Directory.Exists("C:\负屃\" TextBox1.Text) Then '检查文件夹是否存在
Directory.CreateDirectory("C:\负屃\" TextBox1.Text) '不存在,创建文件建夹
End If
你的例子是因为少了一个"\"引起的,正确的如下:
Dim fsotest As New FileSystemObject
If fsotest.FileExists("C:\负屃\" TextBox1.Text) = False Then
fsotest.CreateFolder("C:\负屃\" TextBox1.Text) '这里你少了一个\
End If
MsgBox("创建成功")
vb获取硬件信息的代码
tmpstr=""
set fso=createObject("scripting.filesystemObject")
Set dc = fso.Drives
for each d in dc
If d.isReady Then
tmpstr=tmpstr "磁盘" d.DriveLetter ":" vbcrlf _
"可用空间:" (d.AvailableSpace/1024/1024/1024) " GB" vbcrlf _
"空余空间:" (d.FreeSpace/1024/1024/1024) " GB" vbcrlf _
"总空间大小:" (d.TotalSize/1024/1024/1024) " GB" vbcrlf _
"文件系统:" d.FileSystem vbcrlf _
"驱动器类型:" d.DriveType vbcrlf _
"是否就绪:" d.IsReady vbcrlf _
"路径:" d.Path vbcrlf _
"根目录:" d.RootFolder vbcrlf _
"序列号:" d.SerialNumber vbcrlf _
"共享名:" d.ShareName vbcrlf _
"卷名:" d.VolumeName vbcrlf vbcrlf
End If
Next
msgbox tmpstr
如何用vb.net 调用VBS文件?
一般的VBS程序都是可以写在VB程序里面的 只需要稍加变化 加上些关键字 或者数据类型
如果 你想调用一个VBS程序 也可以使用Shell的方法
当前题目:vb.net的fso net vb
浏览地址:http://hbruida.cn/article/hpocgh.html