vb.net的fso的简单介绍

vb.net 如何移动文件夹?Microsoft.VisualBasic.FileSystem.Rename(原文件夹完整路径名称vb.net的fso,新vb.net的fso的文件夹名称)
Microsoft.VisualBasic.FileSystem.Rename("D:\1", "D:\2\1")‘当路径不对时会把原文件夹剪切到“D:\2\”下面文件夹名称不变
Microsoft.VisualBasic.FileSystem.Rename("D:\1", "D:\2\2")")‘当路径不对时会把原文件夹剪切到“D:\2\”下面文件夹名称更改为 2
Microsoft.VisualBasic.FileSystem.Rename("D:\1", "D:\2")’当路径相同时只改文件夹名称 不移动文件
vb.net中,不使用FSO方法,怎么快速的得到文件夹的大?。?/h2>窗体上添加一个按钮,代码如下:
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作业,打开某一文件夹,将内容倒排,保存到另一文件夹怎么做'这是VBvb.net的fso的要先引用Microsoft Scripting RunTimevb.net的fso,下面的例子是找叫cmd.xxx的文件的
Private Sub Command1_Click()
Dim m_objFSO As New FileSystemObject
Dim objFolderAs Scripting.Folder'文件夹对象
Dim objFileAs Scripting.File'文件对象
Set objFolder = m_objFSO.GetFolder("c:/test")
For Each objFile In objFolder.Files
Dim filenames() As String
filenames = Split(objFile.Name, ".")
If filenames(0) = "cmd" Then
FileCopy objFile.Path, "c:/TestCMD/""newName."filenames(1)
End If
Next objFile
End Sub
-----------------------------------这是VB.net的--------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim files() As String
files = System.IO.Directory.GetFiles("C:/test")
For i = 0 To files.Length - 1
Dim filenames() As String
filenames = files(i).Substring(files(i).LastIndexOf("\") + 1).Split(".")
If filenames(0) = "cmd" Then
FileCopy(files(i), "c:/TestCMD/""newName."filenames(1))
End If
Next
End Sub
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 如何修改TXT内容?楼上的别瞧不起VB6,其实这样的简单问题VB6处理起来也很简单,而且不需要FSO

推荐阅读