当前位置:网站首页>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
边栏推荐
- 面试官:索引为什么会失效?
- 漫画 | 老板裁掉我两周后,又把我请回去,工资翻番!
- visual studio 2015 warning MSB3246
- Interviewer: How is the expired key in Redis deleted?
- How to make good use of builder mode
- 88. (the home of cesium) cesium polymerization figure
- adb控制常用命令
- Comic | Two weeks after the boss laid me off, he hired me back and doubled my salary!
- How to understand the crawler's Scrapy framework in the simplest and most popular way?
- Desthiobiotin-PEG4-Azide_脱硫生物素-叠氮化物 100mg
猜你喜欢
随机推荐
C语言基础[通俗易懂]
visual studio 2015 warning MSB3246
dotnet 通过 WMI 获取系统安装软件
dotnet 使用 lz4net 压缩 Stream 或文件
【2022牛客多校5 A题 Don‘t Starve】DP
Comic | Two weeks after the boss laid me off, he hired me back and doubled my salary!
大资本已开始逃离加密领域?
帝国CMS仿核弹头H5小游戏模板/92game帝国CMS内核仿游戏网整站源码
关于 SAP 电商云 Spartacus UI SSR 的 state transfer 问题
After the tester with 10 years of service "naked resignation" from the big factory...
机器学习_02
About the state transfer problem of SAP e-commerce cloud Spartacus UI SSR
多商户商城系统功能拆解22讲-平台端分销商品
宝塔实测-搭建中小型民宿酒店管理源码
构建Buildroot根文件系统(I.MX6ULL)
Zero-knowledge proof notes - private transaction, pederson, interval proof, proof of ownership
如何最简单、通俗地理解爬虫的Scrapy框架?
adb控制常用命令
链栈的应用
五分钟入门文本处理三剑客grep awk sed