本文整理汇总了C#中Directory.Exists方法的典型用法代码示例。如果您正苦于以下问题:C# Directory.Exists方法的具体用法?C# Directory.Exists怎么用?C# Directory.Exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Directory
的用法示例。
在下文中一共展示了Directory.Exists方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TemporaryLocalDirectory
public TemporaryLocalDirectory(Directory backingDirectory)
{
UnderlyingDirectory = backingDirectory;
if (!UnderlyingDirectory.Exists())
UnderlyingDirectory.Create();
}
示例2: CreateDirectory
public DokanError CreateDirectory(string fileName, DokanFileInfo info)
{
//Console.WriteLine("CreateDirectory: {0}", fileName);
if (fileName == "\\")
{
return DokanError.ErrorSuccess;
}
if (fileName.EndsWith("\\"))
{
fileName = fileName.Substring(0, fileName.Length - 1);
}
Directory dir = new Directory(Util.GetPathDirectory(fileName));
if (!dir.Exists())
{
return DokanError.ErrorPathNotFound;
}
String name = Util.GetPathFileName(fileName);
if (dir.Contains(name))
{
return DokanError.ErrorAlreadyExists;
}
dir.CreateDirectory(name);
return DokanError.ErrorSuccess;
}
示例3: CloseFile
public DokanError CloseFile(string fileName, DokanFileInfo info)
{
//Console.WriteLine("CloseFile: {0}", fileName);
// 可能打开文件时有 deleteOnClose 标记(Windows 8+)
if (info.Context != null)
{
File f = (File)info.Context;
if (f.flagDeleteOnClose)
{
Directory dir = new Directory(Util.GetPathDirectory(f.path));
if (!dir.Exists())
{
return DokanError.ErrorSuccess;
}
String name = Util.GetPathFileName(f.path);
if (!dir.Contains(name))
{
return DokanError.ErrorSuccess;
}
dir.Delete(name);
}
}
return DokanError.ErrorSuccess;
}
示例4: CreateFile
public DokanError CreateFile(string fileName, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info)
{
info.DeleteOnClose = (options & FileOptions.DeleteOnClose) != 0;
//Console.WriteLine("CreateFile: {0}, mode = {1}", fileName, mode);
if (fileName == "\\")
{
return DokanError.ErrorSuccess;
}
Directory dir = new Directory(Util.GetPathDirectory(fileName));
if (!dir.Exists())
{
return DokanError.ErrorPathNotFound;
}
String name = Util.GetPathFileName(fileName);
if (name.Length == 0)
{
return DokanError.ErrorInvalidName;
}
if (name.IndexOfAny(Path.GetInvalidFileNameChars()) > -1)
{
return DokanError.ErrorInvalidName;
}
// dokan API 要求在目标文件是目录时候,设置 info.IsDirectory = true
if (dir.Contains(name) && (dir.GetItemInfo(name).attribute & FileAttributes.Directory) != 0)
{
info.IsDirectory = true;
return DokanError.ErrorSuccess;
}
try
{
File f = new File(fileName, mode);
f.flagDeleteOnClose = info.DeleteOnClose;
info.Context = f;
}
catch (FileNotFoundException)
{
return DokanError.ErrorFileNotFound;
}
catch (IOException)
{
return DokanError.ErrorAlreadyExists;
}
catch (NotImplementedException)
{
return DokanError.ErrorAccessDenied;
}
catch (Exception)
{
return DokanError.ErrorError;
}
return DokanError.ErrorSuccess;
}
示例5: SetFileTime
public DokanError SetFileTime(string fileName, DateTime? creationTime, DateTime? lastAccessTime, DateTime? lastWriteTime, DokanFileInfo info)
{
Directory dir = new Directory(Util.GetPathDirectory(fileName));
if (!dir.Exists())
{
return DokanError.ErrorPathNotFound;
}
String name = Util.GetPathFileName(fileName);
if (!dir.Contains(name))
{
return DokanError.ErrorFileNotFound;
}
dir.SetFileTime(name, creationTime, lastAccessTime, lastWriteTime);
return DokanError.ErrorSuccess;
}
示例6: SetFileAttributes
public DokanError SetFileAttributes(string fileName, FileAttributes attributes, DokanFileInfo info)
{
//Console.WriteLine("SetFileAttribute: {0}", fileName);
Directory dir = new Directory(Util.GetPathDirectory(fileName));
if (!dir.Exists())
{
return DokanError.ErrorPathNotFound;
}
String name = Util.GetPathFileName(fileName);
if (!dir.Contains(name))
{
return DokanError.ErrorFileNotFound;
}
dir.SetFileAttribute(name, attributes);
return DokanError.ErrorSuccess;
}
示例7: SetEndOfFile
public DokanError SetEndOfFile(string fileName, long length, DokanFileInfo info)
{
Directory dir = new Directory(Util.GetPathDirectory(fileName));
if (!dir.Exists())
{
return DokanError.ErrorPathNotFound;
}
String name = Util.GetPathFileName(fileName);
if (!dir.Contains(name))
{
return DokanError.ErrorFileNotFound;
}
INode inode = Disk.iNodes[dir.GetItemINodeIndex(name)];
inode.SetEndOfFile((int)length);
return DokanError.ErrorSuccess;
}
示例8: OpenDirectory
public DokanError OpenDirectory(string fileName, DokanFileInfo info)
{
if (fileName == "\\" || info.IsDirectory)
{
Directory dir = new Directory(fileName);
if (!dir.Exists())
{
return DokanError.ErrorFileNotFound;
}
}
return DokanError.ErrorSuccess;
}
示例9: MoveFile
public DokanError MoveFile(string oldName, string newName, bool replace, DokanFileInfo info)
{
//Console.WriteLine("MoveFile: {0} -> {1}, replace = {2}", oldName, newName, replace);
var dirNameOld = Util.GetPathDirectory(oldName);
var dirNameNew = Util.GetPathDirectory(newName);
if (dirNameNew.IndexOf(dirNameOld) > -1 && dirNameNew != dirNameOld)
{
return DokanError.ErrorError;
}
var dirOld = new Directory(dirNameOld);
var dirNew = new Directory(dirNameNew);
if (!dirOld.Exists() || !dirNew.Exists())
{
return DokanError.ErrorPathNotFound;
}
var nameOld = Util.GetPathFileName(oldName);
var nameNew = Util.GetPathFileName(newName);
if (dirNew.Contains(nameNew))
{
return DokanError.ErrorAlreadyExists;
}
var inode = dirOld.GetItemINodeIndex(nameOld);
dirOld.Delete(nameOld);
dirNew.AddItem(nameNew, inode);
return DokanError.ErrorSuccess;
}
示例10: GetFileInformation
public DokanError GetFileInformation(string fileName, out FileInformation fileInfo, DokanFileInfo info)
{
//Console.WriteLine("GetFileInformation: {0}, isDirectory = {1}", fileName, info.IsDirectory);
if (fileName == "\\" || info.IsDirectory)
{
Directory dir = new Directory(fileName);
if (!dir.Exists())
{
//Console.WriteLine("GetFileInformation: PathNotFound");
fileInfo = new FileInformation();
return DokanError.ErrorPathNotFound;
}
String name;
String path;
if (fileName == "\\")
{
name = "\\"; path = "\\";
}
else
{
name = Util.GetPathFileName(fileName);
path = fileName;
}
fileInfo = new DirectoryItem(name, path, dir.GetSelfINodeIndex()).GetFileInformation();
//Console.WriteLine("GetFileInformation: Success");
return DokanError.ErrorSuccess;
}
{
Directory dir = new Directory(Util.GetPathDirectory(fileName));
if (!dir.Exists())
{
fileInfo = new FileInformation();
return DokanError.ErrorPathNotFound;
}
String name = Util.GetPathFileName(fileName);
if (!dir.Contains(name))
{
fileInfo = new FileInformation();
return DokanError.ErrorPathNotFound;
}
fileInfo = dir.GetItemInfo(name).GetFileInformation();
//Console.WriteLine("GetFileInformation: Success");
return DokanError.ErrorSuccess;
}
}
示例11: FindFiles
public DokanError FindFiles(string fileName, out IList<FileInformation> files, DokanFileInfo info)
{
//Console.WriteLine("FindFiles: {0}", fileName);
var ret = new List<FileInformation>();
var dir = new Directory(fileName);
if (!dir.Exists())
{
files = null;
return DokanError.ErrorPathNotFound;
}
var list = dir.ListDirectory();
foreach (var item in list)
{
ret.Add(item.GetFileInformation());
}
files = ret;
return DokanError.ErrorSuccess;
}
示例12: DeleteDirectory
public DokanError DeleteDirectory(string fileName, DokanFileInfo info)
{
Directory currentDir = new Directory(fileName);
if (!currentDir.Exists())
{
return DokanError.ErrorPathNotFound;
}
// Windows Explorer 将会处理递归删除部分,所以这里不需要处理
if (currentDir.Count() > 0)
{
return DokanError.ErrorDirNotEmpty;
}
Directory dir = new Directory(Util.GetPathDirectory(fileName));
if (!dir.Exists())
{
return DokanError.ErrorPathNotFound;
}
String name = Util.GetPathFileName(fileName);
if (!dir.Contains(name))
{
return DokanError.ErrorFileNotFound;
}
dir.Delete(name);
return DokanError.ErrorSuccess;
}