本文整理汇总了C#中Directory.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# Directory.Delete方法的具体用法?C# Directory.Delete怎么用?C# Directory.Delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Directory
的用法示例。
在下文中一共展示了Directory.Delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: DeleteFile
public DokanError DeleteFile(string fileName, DokanFileInfo info)
{
//Console.WriteLine("DeleteFile: {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.Delete(name);
return DokanError.ErrorSuccess;
}
示例4: 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;
}