1、判断文件/目录是否存在
Try ' 先判断文件是否存在。 If Not File.Exists(TextBox4.Text) Then File.CreateText(TextBox4.Text) '单纯创建文件一般不常用,正常情况下是创建文件然后进行读写操作 'System.IO.File.Create(TextBox4.Text) End If Catch ex As Exception MessageBox.Show(ex.Message) Exit Sub End Try
Try ' 先建立目录以便用于后续的删除示范。 ' If Not Directory.Exists("D:\网易") Then If Not Directory.Exists(TextBox5.Text) Then Directory.CreateDirectory(TextBox5.Text) '如果目录不存在则创建目录 End If ' 启动 Windows 资源管理器。 Process.Start("explorer.exe", TextBox5.Text) Catch ex As Exception MessageBox.Show(ex.Message) Exit Sub End Try
2、创建、复制、移动、删除文件
2.1 获取文件信息(创建时间) FileDateTime(fii(i).FullName) File.GetCreationTime(path)
System.IO.File.Create(Path)'创建文件 System.IO.File.CreateText(Path)'创建文件 System.IO.File.Copy(Path,targetPath) '复制到新位置,不允许覆盖现有文件 也可以'FileCopy(TextBox4.Text, "C:" & "\" & file_name(UBound(file_name))) System.IO.File.Move(SourceFileName, DestFileName) System.IO.File.Delete(Path) '追加 System.IO.File.AppendText '替换 System.IO.File.Replace
3、创建、移动、删除目录
Directory.CreateDirectory(Path) '创建目录 Directory.Move(str1, str2)'移动目录 Directory.Delete(Path)'删除目录
更多操作可以查看(VS支持自动补全功能挺好的)
System.IO之File
https://msdn.microsoft.com/zh-cn/library/system.io.file(v=vs.110).aspx
https://blog.csdn.net/G00d_Boy/article/details/81627647
扫描二维码关注公众号,回复:
8228146 查看本文章