DirectoryExists() public abstract method

public abstract DirectoryExists ( string fullPath ) : bool
fullPath string
return bool
示例#1
0
        public void ExportTo(string directory, Topic root, Func<Topic, string> pathing)
        {
            var fileSystem = new FileSystem();

            string sourceContent = _settings.Root.AppendPath("content");
            if (fileSystem.DirectoryExists(sourceContent))
            {
                fileSystem.CopyToDirectory(sourceContent, directory.AppendPath("content"));
            }

            root.AllTopicsInOrder().Each(topic =>
            {
                var path = pathing(topic);
                var parentDirectory = path.ParentUrl();

                if (parentDirectory.IsNotEmpty())
                {
                    fileSystem.CreateDirectory(directory.AppendPath(parentDirectory));
                }
                

                var text = _generator.Generate(topic);

                // Hoakum
                topic.Substitutions.Each((key, value) =>
                {
                    text = text.Replace(key, value);
                });

                fileSystem.WriteStringToFile(directory.AppendPath(path), text);
            });
        }
示例#2
0
        // Tests if the given path refers to an existing DirectoryInfo on disk.
        //
        // Your application must have Read permission to the directory's
        // contents.
        //
        public static bool Exists(string path)
        {
            try
            {
                if (path == null)
                {
                    return(false);
                }
                if (path.Length == 0)
                {
                    return(false);
                }

                string fullPath = Path.GetFullPath(path);

                return(FileSystem.DirectoryExists(fullPath));
            }
            catch (ArgumentException) { }
            catch (NotSupportedException) { }  // Security can throw this on ":"
            catch (SecurityException) { }
            catch (IOException) { }
            catch (UnauthorizedAccessException) { }

            return(false);
        }
示例#3
0
        public void MoveTo(string destDirName)
        {
            if (destDirName == null)
            {
                throw new ArgumentNullException(nameof(destDirName));
            }
            if (destDirName.Length == 0)
            {
                throw new ArgumentException(SR.Argument_EmptyFileName, nameof(destDirName));
            }
            string destination = Path.GetFullPath(destDirName);

            string destinationWithSeparator = destination;

            if (!PathHelpers.EndsInDirectorySeparator(destinationWithSeparator))
            {
                destinationWithSeparator = destinationWithSeparator + PathHelpers.DirectorySeparatorCharAsString;
            }

            string sourceWithSeparator = PathHelpers.EndsInDirectorySeparator(FullPath)
                ? FullPath : FullPath + PathHelpers.DirectorySeparatorCharAsString;

            if (string.Equals(sourceWithSeparator, destinationWithSeparator, PathInternal.StringComparison))
            {
                throw new IOException(SR.IO_SourceDestMustBeDifferent);
            }

            string sourceRoot      = Path.GetPathRoot(sourceWithSeparator);
            string destinationRoot = Path.GetPathRoot(destinationWithSeparator);

            if (!string.Equals(sourceRoot, destinationRoot, PathInternal.StringComparison))
            {
                throw new IOException(SR.IO_SourceDestMustHaveSameRoot);
            }

            // Windows will throw if the source file/directory doesn't exist, we preemptively check
            // to make sure our cross platform behavior matches NetFX behavior.
            if (!Exists && !FileSystem.FileExists(FullPath))
            {
                throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, FullPath));
            }

            if (FileSystem.DirectoryExists(destination))
            {
                throw new IOException(SR.Format(SR.IO_AlreadyExists_Name, destinationWithSeparator));
            }

            FileSystem.MoveDirectory(FullPath, destination);

            Init(originalPath: destDirName,
                 fullPath: destinationWithSeparator,
                 fileName: _name,
                 isNormalized: true);

            // Flush any cached information about the directory.
            Invalidate();
        }
示例#4
0
        public static void Move(string sourceDirName, string destDirName)
        {
            if (sourceDirName == null)
            {
                throw new ArgumentNullException(nameof(sourceDirName));
            }
            if (sourceDirName.Length == 0)
            {
                throw new ArgumentException(SR.Argument_EmptyFileName, nameof(sourceDirName));
            }

            if (destDirName == null)
            {
                throw new ArgumentNullException(nameof(destDirName));
            }
            if (destDirName.Length == 0)
            {
                throw new ArgumentException(SR.Argument_EmptyFileName, nameof(destDirName));
            }

            string fullsourceDirName = Path.GetFullPath(sourceDirName);
            string sourcePath        = EnsureTrailingDirectorySeparator(fullsourceDirName);

            string fulldestDirName = Path.GetFullPath(destDirName);
            string destPath        = EnsureTrailingDirectorySeparator(fulldestDirName);

            StringComparison pathComparison = PathInternal.StringComparison;

            if (string.Equals(sourcePath, destPath, pathComparison))
            {
                throw new IOException(SR.IO_SourceDestMustBeDifferent);
            }

            string sourceRoot      = Path.GetPathRoot(sourcePath);
            string destinationRoot = Path.GetPathRoot(destPath);

            if (!string.Equals(sourceRoot, destinationRoot, pathComparison))
            {
                throw new IOException(SR.IO_SourceDestMustHaveSameRoot);
            }

            // Windows will throw if the source file/directory doesn't exist, we preemptively check
            // to make sure our cross platform behavior matches NetFX behavior.
            if (!FileSystem.DirectoryExists(fullsourceDirName) && !FileSystem.FileExists(fullsourceDirName))
            {
                throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, fullsourceDirName));
            }

            if (FileSystem.DirectoryExists(fulldestDirName))
            {
                throw new IOException(SR.Format(SR.IO_AlreadyExists_Name, fulldestDirName));
            }

            FileSystem.MoveDirectory(fullsourceDirName, fulldestDirName);
        }
示例#5
0
        public static string RippleDirectory()
        {
            var codeDirectory = CodeDirectory();
            var system = new FileSystem();
            if (system.DirectoryExists(codeDirectory.AppendPath("ripple")))
            {
                return codeDirectory.AppendPath("ripple");
            }

            return codeDirectory.AppendPath("buildsupport");
        }
            private static bool DoesItemExist(ReadOnlySpan <char> path, bool isFile)
            {
                if (path.IsEmpty || path.Length == 0)
                {
                    return(false);
                }

                if (!isFile)
                {
                    return(FileSystem.DirectoryExists(path));
                }

                return(PathInternal.IsDirectorySeparator(path[path.Length - 1])
                    ? false
                    : FileSystem.FileExists(path));
            }
示例#7
0
        // Tests if the given path refers to an existing DirectoryInfo on disk.
        public static bool Exists([NotNullWhen(true)] string?path)
        {
            try
            {
                if (path == null)
                {
                    return(false);
                }
                if (path.Length == 0)
                {
                    return(false);
                }

                string fullPath = Path.GetFullPath(path);

                return(FileSystem.DirectoryExists(fullPath));
            }
            catch (ArgumentException) { }
            catch (IOException) { }
            catch (UnauthorizedAccessException) { }

            return(false);
        }
示例#8
0
 public void FileSystem_DirectoryExists_Finds_Directory()
 {
     IFileSystem fileSystem = new FileSystem();
     var result = fileSystem.DirectoryExists(FileSystemDirectoryExistsFindsDirectoryTarget);
     Assert.IsTrue(result);
 }