示例#1
0
        /**
         * Copies {@code sourceFiles} to the {@code destDir} directory.
         *
         * @param sourceFiles the list of source files.
         * @param destDir the directory to copy the files to.
         * @throws IOException if the copy fails.
         */
        public static void Copy(ImmutableArray <SystemPath> sourceFiles, SystemPath destDir)
        {
            foreach (SystemPath sourceFile in sourceFiles)
            {
                PathConsumer copyPathConsumer =
                    path =>
                {
                    // Creates the same path in the destDir.
                    SystemPath destPath = destDir.Resolve(sourceFile.GetParent().Relativize(path));
                    if (Files.IsDirectory(path))
                    {
                        Files.CreateDirectories(destPath);
                    }
                    else
                    {
                        Files.Copy(path, destPath);
                    }
                };

                if (Files.IsDirectory(sourceFile))
                {
                    new DirectoryWalker(sourceFile).Walk(copyPathConsumer);
                }
                else
                {
                    copyPathConsumer.Accept(sourceFile);
                }
            }
        }
示例#2
0
        /**
         * Walks {@link #rootDir} and applies {@code pathConsumer} to each file. Note that {@link
         * #rootDir} itself is visited as well.
         *
         * @param pathConsumer the consumer that is applied to each file.
         * @return a list of Paths that were walked.
         * @throws IOException if the walk fails.
         */
        public ImmutableArray <SystemPath> Walk(PathConsumer pathConsumer)
        {
            ImmutableArray <SystemPath> files = Walk();

            foreach (SystemPath path in files)
            {
                pathConsumer.Accept(path);
            }
            return(files);
        }