C#创建文件夹结构的最佳方法
我想自动生成不同的文件夹结构(作为新视频/电影编辑项目的准备)。它还允许在每个文件夹结构中添加特殊文件夹,如After Effects和Photoshop 它应该从配置文件中读取结构,然后创建文件夹 我当前的代码如下所示:C#创建文件夹结构的最佳方法,c#,directory,directory-structure,C#,Directory,Directory Structure,我想自动生成不同的文件夹结构(作为新视频/电影编辑项目的准备)。它还允许在每个文件夹结构中添加特殊文件夹,如After Effects和Photoshop 它应该从配置文件中读取结构,然后创建文件夹 我当前的代码如下所示: if(tbPath.Text == "_______________________________________________________" || tbConfigPath.Text == "________________________
if(tbPath.Text == "_______________________________________________________"
|| tbConfigPath.Text == "_______________________________________________________"
|| tbPath.Text == ""
|| tbConfigPath.Text == "")
{
System.Windows.MessageBox.Show("You didn't enter a valid Path.", "Invalid Path", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
//List for the paths
List<string> paths = new List<string>();
List<string> finalpaths = new List<string>();
string outPath = tbPath.Text;
//Where to get the config from
string configPath = tbConfigPath.Text;
string line = "";
// Read the file and display it line by line.
System.IO.StreamReader file = new System.IO.StreamReader(configPath);
while ((line = file.ReadLine()) != null)
{
paths.Add(line);
}
file.Close();
for (int i = 0; i < paths.Count(); i++)
{
finalpaths.Add(outPath + paths[i]);
}
//----------------Folder Generatring------------
for (int i = 0; i < paths.Count(); i++)
{
Directory.CreateDirectory(finalpaths[i]);
}
// Add After Effects
if (cbAE.IsChecked == true)
{
string AEpath = outPath + "\\AfterEffects";
Directory.CreateDirectory(AEpath);
}
// Add Photoshop
if (cbAE.IsChecked == true)
{
string PSpath = outPath + "\\Photoshop";
Directory.CreateDirectory(PSpath);
}
System.Windows.MessageBox.Show("The folders where generated successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
pgStartUp pgStart = new pgStartUp();
NavigationService.Navigate(pgStart);
if(tbPath.Text==“\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
||tbConfigPath.Text=“\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
||tbPath.Text==“”
||tbConfigPath.Text==“”)
{
System.Windows.MessageBox.Show(“您没有输入有效路径。”,“无效路径”,MessageBoxButton.OK,MessageBoxImage.Error);
返回;
}
//路径列表
列表路径=新列表();
List finalPath=新列表();
字符串outPath=tbPath.Text;
//从何处获取配置
字符串configPath=tbConfigPath.Text;
字符串行=”;
//读取文件并逐行显示。
System.IO.StreamReader文件=新的System.IO.StreamReader(configPath);
而((line=file.ReadLine())!=null)
{
路径。添加(行);
}
file.Close();
对于(int i=0;i
但我觉得这不是很有效。有没有更好的方法?当您使用:
Directory.CreateDirectory(path);
此行将在作为参数传递的路径字符串中创建所有或缺少的目录。所以你不需要其他任何东西
所有逻辑都可以创建一个正确的路径字符串,同时考虑根目录和类似的内容。当您使用:
Directory.CreateDirectory(path);
此行将在作为参数传递的路径字符串中创建所有或缺少的目录。所以你不需要其他任何东西
所有逻辑都可以创建一个正确的路径字符串,同时考虑根目录等