当前位置:网站首页>C# FileInfo class
C# FileInfo class
2022-08-02 07:18:00 【flysh05】
FileInfo Several basic methods of the class:
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();
- 获取文件名称,文件全路径,文件路径,文件大小,read-only property
//使用绝对路径
//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} 不存在!");
}
边栏推荐
猜你喜欢
[数据集][VOC]眼睛佩戴数据集VOC格式6000张
Analysis of the source code of the JS UI framework of Hongmeng system
Kingdee International: Lost in half a year and last year, how does the business model of frantically burning money continue
享年94岁,图灵奖得主、计算复杂性理论先驱Juris Hartmanis逝世
GCC编译器技术解析
Reverse resolve dns server
MySQL - 多表查询与案例详解
Xgboost报错 ValueError: Invalid shape: (1650, 2) for label
MySQL (3)
MySQL高级语句(一)
随机推荐
MySQL Advanced Study Notes
享年94岁,图灵奖得主、计算复杂性理论先驱Juris Hartmanis逝世
【21天学习挑战赛】顺序查找
How the Internet of Things is changing the efficiency of city operations
How to install the specified version package with NPM and view the version number
MySQL高级-MVCC(超详细整理)
C# FileInfo类
BGP+MPLS Comprehensive Experiment
PHP Warning: putenv() has been disabled for security reasons in phar
typescript 'props' is declared but its value is never read solution
npm ---- install yarn
MySql - there is no insert, there is update or ignored
CAT1 4G+以太网开发板腾讯云手机微信小程序显示温度和下发控制
optional
npm 和 yarn的区别
rhce homework
Toolbox App 1.25 New Features at a Glance | Version Update
MySQL索引常见面试题(2022版)
postgres 多个变量填充字符串,字串格式化
(笔记整理未完成)【图论】图的遍历