C# 查找所有可能的文件路径排列
我试图找到给定文件路径的所有可能排列。在传输某些文件之前,需要在远程服务器上创建一些目录 这是我的密码C# 查找所有可能的文件路径排列,c#,C#,我试图找到给定文件路径的所有可能排列。在传输某些文件之前,需要在远程服务器上创建一些目录 这是我的密码 public class PathUtils { public bool IsUNC(String path) { string root = Path.GetPathRoot(path); return root.StartsWith(new String(Path.DirectorySeparatorChar, 2)); }
public class PathUtils
{
public bool IsUNC(String path)
{
string root = Path.GetPathRoot(path);
return root.StartsWith(new String(Path.DirectorySeparatorChar, 2));
}
public void Combinations(HashSet<String> paths, String path)
{
if (!Path.HasExtension(path) && !path.EndsWith(Path.DirectorySeparatorChar.ToString()))
{
path = path + Path.DirectorySeparatorChar;
}
if (IsUNC(path))
{
paths.Add(new String(Path.DirectorySeparatorChar, 2) + (new Uri(path)).Host);
}
String previous = path;
while (!String.IsNullOrEmpty(Path.GetDirectoryName(previous)))
{
paths.Add(Path.GetDirectoryName(previous));
previous = Path.GetDirectoryName(previous);
}
paths.Add(Path.GetPathRoot(path));
}
}
公共类路径
{
公共bool IsUNC(字符串路径)
{
string root=Path.GetPathRoot(路径);
返回root.StartsWith(新字符串(Path.directoryseportorchar,2));
}
公共void组合(哈希集路径、字符串路径)
{
if(!Path.HasExtension(Path)和&!Path.EndsWith(Path.directoryseportorchar.ToString())
{
path=path+path.directoryseportorchar;
}
if(IsUNC(路径))
{
Add(新字符串(Path.directoryseportorchar,2)+(新Uri(Path)).Host);
}
字符串previous=路径;
而(!String.IsNullOrEmpty(Path.GetDirectoryName(上一个)))
{
Add(Path.GetDirectoryName(previous));
previous=Path.GetDirectoryName(previous);
}
Add(Path.GetPathRoot(Path));
}
}
然而,当我给它一个PRTK 7.0.0\KEYLOK 1.6
的path
时,哈希集中返回的唯一值是PRTK 7.0.0
当应该有两个时,PRTK 7.0.0
和KEYLOK 1.6
。如果我提供一个路径PRTK 7.0.0\KEYLOK 16
,我将得到预期的结果,即hashset中的两个项-PRTK 7.0.0
和KEYLOK 16
我不确定为什么会发生这种行为,我们非常感谢您的帮助 迂腐的警告:
\\?\UNC\server\share
也是一个。另外,您是否使用排列的数学定义?您确定不是指路径组件吗?path.HasExtension(@“PRTK 7.0.0\KEYLOK 1.6”)
返回true
。您可能需要使用来消除目录中包含
和扩展名为的文件之间的歧义。迂腐的警告:\\?\UNC\server\share
也是。此外,您是否使用排列的数学定义?您确定不是指路径组件吗?path.HasExtension(@“PRTK 7.0.0\KEYLOK 1.6”)
返回true
。您可能需要使用来消除目录中包含
和文件扩展名之间的歧义。