如何检查文件夹名称是否符合要求
how to check if folder name meets requirement
用户应该将文件夹放入目录
string sourcepath
如何检查目录中的所有文件夹和文件是否具有正确的 "numbers space numbers space numbers space" 格式,例如“123 456 789” 我会想到伪代码
会是这样的:
DirectoryInfo parentFolderInfo = new DirectoryInfo(sourcePath);
foreach (DirectoryInfo folder in parentFolderInfo.GetDirectories())
{
if (sourcepath == "correct name")
{
FileInfo[] filesInSource = folder.GetFiles();
foreach (FileInfo file in filesInSource)
{
if (file == "correct name")
{
//do something
}
else
{
//return box "the folder name is wrong please try again
}
}
}
else
{
//return box "the folder name is wrong please try again
}
我想我们必须为此使用正则表达式。谢谢
static string pattern = "((.*))([(.*)^\s])([^\(_.*)]+)([^\s]+)";//change the regex ass needed
static Match result;
static string formatname = string.Empty;
DirectoryInfo parentFolderInfo = new DirectoryInfo(sourcePath);
foreach (DirectoryInfo folder in foldersInSource.GetDirectories())//This loops through all folders from path
{
formatname = fileNameVaild.Name;//This gets the folder name
result = Regex.Match(fileNameVaild.Name, pattern);//This compares the two values
if (result.Value == formatname)
{
continue;
}
else
{
return false;//if values != then return false.
}
}
我希望这能让某人开始。
用户应该将文件夹放入目录
string sourcepath
如何检查目录中的所有文件夹和文件是否具有正确的 "numbers space numbers space numbers space" 格式,例如“123 456 789” 我会想到伪代码 会是这样的:
DirectoryInfo parentFolderInfo = new DirectoryInfo(sourcePath);
foreach (DirectoryInfo folder in parentFolderInfo.GetDirectories())
{
if (sourcepath == "correct name")
{
FileInfo[] filesInSource = folder.GetFiles();
foreach (FileInfo file in filesInSource)
{
if (file == "correct name")
{
//do something
}
else
{
//return box "the folder name is wrong please try again
}
}
}
else
{
//return box "the folder name is wrong please try again
}
我想我们必须为此使用正则表达式。谢谢
static string pattern = "((.*))([(.*)^\s])([^\(_.*)]+)([^\s]+)";//change the regex ass needed
static Match result;
static string formatname = string.Empty;
DirectoryInfo parentFolderInfo = new DirectoryInfo(sourcePath);
foreach (DirectoryInfo folder in foldersInSource.GetDirectories())//This loops through all folders from path
{
formatname = fileNameVaild.Name;//This gets the folder name
result = Regex.Match(fileNameVaild.Name, pattern);//This compares the two values
if (result.Value == formatname)
{
continue;
}
else
{
return false;//if values != then return false.
}
}
我希望这能让某人开始。