当前位置: 首页>>代码示例>>C#>>正文


C# Directory.Exists方法代码示例

本文整理汇总了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();
        }
开发者ID:DotNetIO,项目名称:DotNetIO,代码行数:7,代码来源:TemporaryLocalDirectory.cs

示例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;
        }
开发者ID:WishSummer,项目名称:FS,代码行数:31,代码来源:FSDrive.cs

示例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;
        }
开发者ID:WishSummer,项目名称:FS,代码行数:29,代码来源:FSDrive.cs

示例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;
        }
开发者ID:WishSummer,项目名称:FS,代码行数:59,代码来源:FSDrive.cs

示例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;
        }
开发者ID:WishSummer,项目名称:FS,代码行数:16,代码来源:FSDrive.cs

示例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;
        }
开发者ID:WishSummer,项目名称:FS,代码行数:18,代码来源:FSDrive.cs

示例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;
        }
开发者ID:WishSummer,项目名称:FS,代码行数:18,代码来源:FSDrive.cs

示例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;
 }
开发者ID:WishSummer,项目名称:FS,代码行数:12,代码来源:FSDrive.cs

示例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;
        }
开发者ID:WishSummer,项目名称:FS,代码行数:33,代码来源:FSDrive.cs

示例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;
            }
        }
开发者ID:WishSummer,项目名称:FS,代码行数:54,代码来源:FSDrive.cs

示例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;
        }
开发者ID:WishSummer,项目名称:FS,代码行数:22,代码来源:FSDrive.cs

示例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;
        }
开发者ID:WishSummer,项目名称:FS,代码行数:30,代码来源:FSDrive.cs


注:本文中的Directory.Exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。