当前位置:网站首页>C# FileInfo类
C# FileInfo类
2022-08-02 05:42:00 【flysh05】
FileInfo 类的几个基本方法:
1. 创建文件
FileInfo fInfo = new FileInfo("Sample.txt");
if (!fInfo.Exists)
{
fInfo.Create();
}
2. 复制文件
FileInfo fInfo = new FileInfo("Sample.txt");
//目标文件存在则覆盖
fInfo.CopyTo("SampleCopy.txt", true);
3. 移动文件,重名文件
FileInfo fInfo = new FileInfo("Sample.txt");
fInfo.MoveTo("MoveSample.txt");//重命名
4. 删除文件
FileInfo fInfo = new FileInfo("Sample.txt");
fInfo.Delete();
- 获取文件名称,文件全路径,文件路径,文件大小,是否只读属性
//使用绝对路径
//C:\Users\Desktop\文件操作\FileAndFolder\bin\Debug\TestFile.txt
//使用相对路径
FileInfo fInfo = new FileInfo("TestFile.txt");
//判断文件是否存在 Exists属性
if (fInfo.Exists)
{
ShowMsg($"{
fInfo.FullName} 存在!");
ShowMsg($"文件名:{
fInfo.Name}");
ShowMsg($"文件路径:{
fInfo.Directory}");
ShowMsg($"文件大小:{
fInfo.Length} byte");
ShowMsg($"文件是否只读:{
fInfo.IsReadOnly}");
}
else
{
ShowMsg($"{
fInfo.FullName} 不存在!");
}
边栏推荐
- The stock price has repeatedly hit new lows, and the real estate SaaS giant is in trouble. How should Mingyuan Cloud transform and save itself?
- [OpenCV from entry to practice] image processing technology [pixel] (the most detailed in the whole network)
- Xgboost报错 ValueError: Invalid shape: (1650, 2) for label
- 股价屡创新低 地产SaaS巨头陷入困境 明源云该如何转型自救?
- Node的安装与环境变量的配置
- C# Coding Conventions Handbook
- MySQL高级-MVCC(超详细整理)
- Luogu mini game Daquan (everyone who uses Luogu must know)
- node安装和配置(node-v12.20.2-x64 ) 以及node版本切换介绍
- 秒杀系统小demo
猜你喜欢
随机推荐
MySQL - 多表查询与案例详解
oracle 远程连接数据库
HCIP BGP综合实验 建立对等体、路由反射器、联邦、路由宣告及聚合
Kingdee International: Lost in half a year and last year, how does the business model of frantically burning money continue
Double for loop case (use js jiujiu printing multiplication table)
flex layout (flexible layout)
How the Internet of Things is changing the efficiency of city operations
MySql 5.7.38下载安装教程 ,并实现在Navicat操作MySql
npm、cnpm的安装
引领需求 为HR价值正名——“人力资源领先模型HRLM”成功首发
MySQL union query (multi-table query)
npm 和 yarn的区别
Toolbox App 1.25 New Features at a Glance | Version Update
BGP experiment (route reflector, federation, route optimization)
股价屡创新低 地产SaaS巨头陷入困境 明源云该如何转型自救?
MySQL(3)
Nacos客户端启动出现9848端口错误分析(非版本升级问题)
Technology empowers Lhasa's "lungs", Huawei helps Lalu Wetland Smart Management to protect lucid waters and lush mountains
BGP+MPLS综合实验
触发器简单解释









