比如:给C:\PLMLoggerData路径下创建一个名为档案的文件夹:
1、DirectoryInfo类的部分代码为下:
[Serializable]
[ComVisible(true)]
public sealed class DirectoryInfo : FileSystemInfo
{
[SecuritySafeCritical]
public DirectoryInfo(string path)
{
if (path == null)
{
throw new ArgumentNullException("path");
}
Init(path, checkHost: true);
}
[SecurityCritical]
private void Init(string path, bool checkHost)
{
if (path.Length == 2 && path[1] == ':')
{
OriginalPath = ".";
}
else
{
OriginalPath = path;
}
string fullPathAndCheckPermissions = Directory.GetFullPathAndCheckPermissions(path, checkHost);
FullPath = fullPathAndCheckPermissions;
base.DisplayPath = GetDisplayName(OriginalPath, FullPath);
}
private static string GetDisplayName(string originalPath, string fullPath)
{
string text = "";
if (originalPath.Length == 2 && originalPath[1] == ':')
{
return ".";
}
return originalPath;
}
}
2、创建文件夹的部分代码:
DirectoryInfo bagdi = new DirectoryInfo(string.Format(@"{0}\{1}", "C:\PLMLoggerData", "档案");
if (!bagdi.Exists)
{
bagdi.Create();
}