当前位置:网站首页>Rename directory in C [closed] - renaming a directory in C [closed]
Rename directory in C [closed] - renaming a directory in C [closed]
2022-07-05 07:37:00 【French red wine sweet】
problem :
I couldn't find a DirectoryInfo.Rename(To) or FileInfo.Rename(To) method anywhere. I can't find it anywhere DirectoryInfo.Rename(To) or FileInfo.Rename(To) Method .So, I wrote my own and I'm posting it here for anybody to use if they need it, because let's face it : the MoveTo methods are overkill and will always require extra logic if you just want to rename a directory or file : therefore , I wrote my own , I post it here , For anyone to use , If they need it , Because let's face it :MoveTo The method is excessive , If you just want to rename a directory or file , Additional logic will always be needed :
public static class DirectoryExtensions{ public static void RenameTo(this DirectoryInfo di, string name) { if (di == null) { throw new ArgumentNullException("di", "Directory info to rename cannot be null"); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("New name cannot be null or blank", "name"); } di.MoveTo(Path.Combine(di.Parent.FullName, name)); return; //done }}
Solution :
Reference resources : https://stackoom.com/en/question/8UWl边栏推荐
- Self summary of college life - freshman
- Rough notes of C language (1)
- Apple system shortcut key usage
- Light up the running light, rough notes for beginners (1)
- Reading literature sorting 20220104
- Professional knowledge of public security -- teacher bilitong
- Numpy——1.數組的創建
- Idea shortcut key
- Differences between pycharm and idle and process -- join() in vs Code
- Rough notes of C language (2) -- constants
猜你喜欢
随机推荐
Selenium element positioning
Simple operation of nixie tube (keil5)
Apple system shortcut key usage
I 用c I 实现队列
大学生活的自我总结-大一
UNIX commands often used in work
Simple use of timeunit
Detour of Tkinter picture scaling
How to delete the virus of inserting USB flash disk copy of shortcut to
What is soda?
selenium 元素定位
CADD course learning (5) -- Construction of chemosynthesis structure with known target (ChemDraw)
arcpy. SpatialJoin_ Analysis spatial connection analysis
repo. conda. An example of COM path error
QT small case "addition calculator"
Rough notes of C language (1)
Day01 markdown log entry tips
(tool use) how to make the system automatically match and associate to database fields by importing MySQL from idea and writing SQL statements
cygwin
Basic series of SHEL script (I) variables