当前位置:网站首页>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} 不存在!");
}
边栏推荐
- npm、nrm两种方式查看源和切换镜像
- Node installation and configuration (node-v12.20.2-x64 ) and introduction to node version switching
- MySQL高级语句(一)
- pointer arithmetic in c language
- Xgboost报错 ValueError: Invalid shape: (1650, 2) for label
- 提交代码流程
- DNS的解析流程
- MySQL database video tutorial from beginner to proficient
- MySQL高级-MVCC(超详细整理)
- MySQL高级学习笔记
猜你喜欢
Kind of weird!Access the destination URL, the host can container but not
Practice on optimizing startup performance of VS Code
How to install the specified version package with NPM and view the version number
Node installation and configuration of environment variables
Xgboost报错 ValueError: Invalid shape: (1650, 2) for label
MySQL classic 50 practice questions and the most detailed analysis of the whole network
How the Internet of Things is changing the efficiency of city operations
Thread Basics (1)
nodejs的安装和全局配置(超详细哦)
leetcode-318.最大单词长度乘积
随机推荐
leetcode solves the linked list merge problem in one step
MySql -- 不存在则插入,存在则更新或忽略
深入剖析成员变量和局部变量的初始化问题
MySQL高级-MVCC(超详细整理)
View source and switch mirrors in two ways: npm and nrm
Node installation and environment configuration
推出 Space On-Premises (本地部署版) Beta 版!
8/1 思维+扩展欧几里得+树上dp
zabbix自动发现和自动注册
Xgboost报错 ValueError: Invalid shape: (1650, 2) for label
selenium + robotframework的运行原理
人工神经网络
Go inside the basic knowledge
Dataset: A detailed guide to the download link collection of commonly used datasets in machine learning
MarkDown公式指导手册
APP专项测试:流量测试
BGP+MPLS Comprehensive Experiment
npm、nrm两种方式查看源和切换镜像
直播系统聊天技术(八):vivo直播系统中IM消息模块的架构实践
How to perform concurrent calculation (stability test and stress test)?