当前位置:网站首页>C WinForm development file / folder creation
C WinForm development file / folder creation
2022-07-22 21:43:00 【A chicken with multiple senses】
ControlFileClass Class CreateFolder and CreateFile function :
/// <summary>
/// Create folder
/// </summary>
/// <param name="dirPath"> Folder path </param>
/// <param name="name"> Folder name </param>
public static void CreateFolder(string dirPath, string name)
{
foreach (string d in Directory.GetFileSystemEntries(dirPath))
{
if (File.Exists(dirPath + @"\" + name))
{
Console.WriteLine(" Create folder " + name + " Failure , Folder already exists ");
return;
}
}//end of for
DirectoryInfo info = new DirectoryInfo(dirPath);
info.CreateSubdirectory(name);
//info.Parent.CreateSubdirectory(name);// You can generate folders in the parent directory , Very convenient
}//end of CreateFolder
/// <summary>
/// create a file
/// </summary>
/// <param name="dirPath"> File path </param>
/// <param name="name"> file name </param>
public static void CreateFile(string dirPath, string name)
{
foreach (string d in Directory.GetFileSystemEntries(dirPath))
{
if (File.Exists(dirPath + @"\" + name))
{
Console.WriteLine(" create a file " + name + " Failure , The file already exists ");
return;
}
}//end of for
File.Create(dirPath + @"\" + name);
}//end of CreateFile
Simple example :
ControlFileClass.CreateFolder(rootPath,"wybnmsl");
ControlFileClass.CreateFile(rootPath,"2.txt");
边栏推荐
猜你喜欢
随机推荐
Why do independent business owners accept CTSI
ActiveMQ持久化步骤
记录:问题1,电脑闪屏;问题2,电脑桌面图标双击没有反应
pytorch, 指定显卡问题
Run pychar on the server. Prompt: already running
C# Winform开发 窗体间的数据交互
校园IP网络广播案例-石家庄法商中等专业学校鹿泉校区校园IP广播系统应用
Servlet
Solve problems encountered when compiling mosquitto
Network Accounting - layered structure, OSI communication process, tcp/ip model and 5-layer reference model
四六级英语听力发射无线广播系统在广东海洋大学阳江校区的应用
Character processing command
Environment variable configuration file
Bash variable -- position parameter variable
Makefile心得
煤矿无线广播系统解决方案
自动化测试Json通用解析器
2022年Q2行业展望及Portfolio项目进展
二分-机器人跳跃问题
extern “C“的作用