如何确定某个文件是否位于使用C#的SUBST'ed或位于用户文件夹中的文件夹中?如何确定一个目录路径是否被隐藏
回答
我认为你需要P/Invoke QueryDosDevice()作为盘符。 Subst驱动器将返回一个符号链接,类似于\ ?? \ C:\ blah。 \ ?? \前缀表示它被替换,其余的则为您提供drive +目录。
如果SUBST运行时没有参数,它会生成所有当前替换的列表。获取列表,并根据列表检查您的目录。
还有一个将卷映射到目录的问题。我从来没有试图检测到这些,但挂载点目录显示的不同于普通目录,因此它们必须具有某种不同的属性,并且可以检测到这些属性。
我觉得你有几个选择 -
通过System.Management类: http://briancaos.wordpress.com/2009/03/05/get-local-path-from-unc-path/
或者
通过P /调用此MAPI函数: ScUNCFromLocalPath http://msdn.microsoft.com/en-us/library/cc842520.aspx
这看起来很有希望,看着它 – petejamd 2010-06-10 17:36:16
这是我使用来获取信息,如果路径substed代码: (部分来自pinvoke)
[DllImport("kernel32.dll", SetLastError=true)]
static extern uint QueryDosDevice(string lpDeviceName, StringBuilder lpTargetPath, int ucchMax);
public static bool IsSubstedPath(string path, out string realPath)
{
StringBuilder pathInformation = new StringBuilder(250);
string driveLetter = null;
uint winApiResult = 0;
realPath = null;
try
{
// Get the drive letter of the path
driveLetter = Path.GetPathRoot(path).Replace("\\", "");
}
catch (ArgumentException)
{
return false;
//<------------------
}
winApiResult = QueryDosDevice(driveLetter, pathInformation, 250);
if(winApiResult == 0)
{
int lastWinError = Marshal.GetLastWin32Error(); // here is the reason why it fails - not used at the moment!
return false;
//<-----------------
}
// If drive is substed, the result will be in the format of "\??\C:\RealPath\".
if (pathInformation.ToString().StartsWith("\\??\\"))
{
// Strip the \??\ prefix.
string realRoot = pathInformation.ToString().Remove(0, 4);
// add backshlash if not present
realRoot += pathInformation.ToString().EndsWith(@"\") ? "" : @"\";
//Combine the paths.
realPath = Path.Combine(realRoot, path.Replace(Path.GetPathRoot(path), ""));
return true;
//<--------------
}
realPath = path;
return false;
}
请确保你在你的班级 using System.Runtime.InteropServices; 否则你会得到错误。 – gg89 2016-09-23 05:11:06
- 1. 如何确定路径是否在目录中? (POSIX)
- 2. 给定一个路径,如何确定它是目录还是文件
- 3. 如何测试一个目录是否是python模块路径?
- 4. 确定NSString中的路径是否是目录或文件?
- 5. JQuery - 如何确定一个DOM元素是否“隐藏”?
- 6. GNU make,如何确定路径是文件还是目录?
- 7. 验证是否路径指向另一个路径给定目录
- 8. 如何创建一个隐藏目录
- 9. 确定3D对象是否被另一3D对象隐藏
- 10. 如何将一个目录变成一个隐藏的目录
- 11. Mac OS:如何确定路径是文件或目录
- 12. 如何确定路径是vb6中的文件或目录?
- 13. 确定一个路径是否在Ruby的另一个路径下?
- 14. 如何确定一个目录是否在同一分区
- 15. 代码隐藏当前目录的相对路径不一致
- 16. 如何检查路径是否指定卷根目录
- 17. 你如何确定一个项目是否被选中?
- 18. 如何检查路径的目标是否是目录?
- 19. Django MissingFileError:路径是一个目录
- 20. Python为什么文件路径被认为是一个目录
- 21. 如何确定某个点是否隐藏在投影中?
- 22. c#检查一个目录是否隐藏?
- 23. 确定两个目录名是否指向同一目录
- 24. 确定路径是否是在Javascript
- 25. 像puu.sh隐藏图像路径确实
- 26. 检查一个目录是否存在递归反转路径
- 27. 检查一个目录是否存在绝对路径
- 28. 一个项目被隐藏在引导
- 29. 如何隐藏SD卡路径名?
- 30. 如何隐藏实际路径Carrierwave
我不明白你所说的“subst'd”或“是什么意思用户文件夹“ – simendsjo 2010-06-10 16:13:43
'subst'是一个dos命令,它将为一个目录创建一个别名(例如,'subst T:C:\ workareas'将为用户文件夹创建一个指向C:\ workareas的新驱动器) ,想找出它是否在'C:\ Documents and Settings \%username%'干净。 – petejamd 2010-06-10 17:35:25