当前位置:网站首页>dotnet delete read-only files
dotnet delete read-only files
2022-08-04 20:57:00 【Lin Dexi】
If you delete a read-only file directly through File.Delete, there will be no permission prompt, you can first set the file to not be read-only and then delete the file
try{File.Delete(file);}catch (UnauthorizedAccessException){File.SetAttributes(file, FileAttributes.Normal);File.Delete(file);}
The above code is to first try to delete the file, if the deletion fails, then set the file to not read-only, and then try to delete the file
Why do you need to try to delete first? The reason is that if you try to modify a file before deleting it, the performance is not good.
If there is no exception in Try, then the code entering the Try is the same as the code that does not enter the Try
边栏推荐
猜你喜欢
MATLAB中readtimetable函数用法
长时间序列遥感数据处理及在全球变化、物候提取、植被变绿与固碳分析、生物量估算与趋势分析等领域中的应用
大资本已开始逃离加密领域?
How to understand the crawler's Scrapy framework in the simplest and most popular way?
【手把手教你使用STM32HAL库的串口空闲中断】
【一起学Rust | 进阶篇 | Service Manager库】Rust专用跨平台服务管理库
二叉搜索树解决硬木问题
mdk5.14 cannot be burned
Five Minutes Introductory Text Processing Three Musketeers grep awk sed
Zero-knowledge proof notes - private transaction, pederson, interval proof, proof of ownership
随机推荐
dotnet 启动 JIT 多核心编译提升启动性能
链栈的应用
工龄10年的测试员从大厂“裸辞”后...
mdk5.14无法烧录
【debug】postgres数据存储错乱
dotnet 删除只读文件
关于 SAP 电商云 Spartacus UI SSR 的 state transfer 问题
[Data Mining] Written Exam Questions for Sohu Data Mining Engineers
jekyll adds a flowchart to the blog
How to train a deep learning model?
matlab 画图
After encountering MapStruct, the conversion between PO, DTO and VO objects is no longer handwritten
After the tester with 10 years of service "naked resignation" from the big factory...
Tear down the underlying mechanism of the five JOINs of SparkSQL
该如何训练好深度学习模型?
xss课堂内容复现
88.(cesium之家)cesium聚合图
经验分享|盘点企业进行知识管理时的困惑类型
【手把手教你使用STM32HAL库的串口空闲中断】
How to carry out AI business diagnosis and quickly identify growth points for cost reduction and efficiency improvement?