当前位置:网站首页>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
边栏推荐
- After encountering MapStruct, the conversion between PO, DTO and VO objects is no longer handwritten
- How to train a deep learning model?
- adb shell input keyevent 模拟按键事件
- 知识分享|如何设计有效的帮助中心,不妨来看看以下几点
- 【编程思想】
- [Academic related] Tsinghua professor persuaded to quit his Ph.D.:I have seen too many doctoral students have mental breakdowns, mental imbalances, physical collapses, and nothing!...
- How to understand the crawler's Scrapy framework in the simplest and most popular way?
- CAS :80750-24-9(脱硫生物素 NHS 酯)
- 路由中的meta、params传参的一些问题(可传不可传,为空,搭配,点击传递多次参数报错)
- bracket matching
猜你喜欢

构建Buildroot根文件系统(I.MX6ULL)

Getting Started with Lattice Passwords

ts集成和使用

【手把手教你使用STM32HAL库的串口空闲中断】

How to carry out AI business diagnosis and quickly identify growth points for cost reduction and efficiency improvement?

Zero-knowledge proof notes - private transaction, pederson, interval proof, proof of ownership

明明加了唯一索引,为什么还是产生了重复数据?

文章复现:超分辨率网络-VDSR

帝国CMS仿核弹头H5小游戏模板/92game帝国CMS内核仿游戏网整站源码

PowerCLi 批量配置NTP
随机推荐
【2022杭电多校5 1012题 Buy Figurines】STL的运用
嵌入式分享合集28
Common methods of js's new Function()
CAS :80750-24-9(脱硫生物素 NHS 酯)
用 Excel 爬取网络数据的四个小案例
某男子因用本地虚拟机做压测,惨遭字节面试官当场嘲笑
After the tester with 10 years of service "naked resignation" from the big factory...
简述@RequestParam与@RequestBody参数注解
【1403. 非递增顺序的最小子序列】
Cryptography Series: PEM and PKCS7, PKCS8, PKCS12
顺序队列
动态数组底层是如何实现的
[2022 Hangzhou Electric Multi-School 5 1003 Slipper] Multiple Super Source Points + Shortest Path
visual studio 2015 warning MSB3246
伺服电机矢量控制原理与仿真(1)控制系统的建立
jekyll 在博客添加流程图
Apache服务器配置多个站点
[Data Mining] Written Exam Questions for Sohu Data Mining Engineers
visual studio 2015 warning MSB3246
【2022牛客多校5 A题 Don‘t Starve】DP