Beispiel #1
0
        private void DirectoryInfo_Attributes(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder  = tempRoot.RandomDirectoryFullPath;
                var dirInfo = new Alphaleonis.Win32.Filesystem.DirectoryInfo(folder + "-AlphaFS");

                Console.WriteLine("Input Directory Path: [{0}]", dirInfo.FullName);

                dirInfo.Create();


                dirInfo.Attributes |= System.IO.FileAttributes.ReadOnly;
                Assert.IsTrue((dirInfo.Attributes & System.IO.FileAttributes.ReadOnly) != 0, "The directory is not ReadOnly, but is expected to.");

                dirInfo.Attributes &= ~System.IO.FileAttributes.ReadOnly;
                Assert.IsTrue((dirInfo.Attributes & System.IO.FileAttributes.ReadOnly) == 0, "The directory is ReadOnly, but is expected not to.");


                dirInfo.Attributes |= System.IO.FileAttributes.Hidden;
                Assert.IsTrue((dirInfo.Attributes & System.IO.FileAttributes.Hidden) != 0, "The directory is not Hidden, but is expected to.");

                dirInfo.Attributes &= ~System.IO.FileAttributes.Hidden;
                Assert.IsTrue((dirInfo.Attributes & System.IO.FileAttributes.Hidden) == 0, "The directory is Hidden, but is expected not to.");


                dirInfo.Attributes |= System.IO.FileAttributes.System;
                Assert.IsTrue((dirInfo.Attributes & System.IO.FileAttributes.System) != 0, "The directory is not System, but is expected to.");

                dirInfo.Attributes &= ~System.IO.FileAttributes.System;
                Assert.IsTrue((dirInfo.Attributes & System.IO.FileAttributes.System) == 0, "The directory is System, but is expected not to.");
            }

            Console.WriteLine();
        }
Beispiel #2
0
        private void DirectoryInfo_FolderName255Characters(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.Directory.FullName;

                Console.WriteLine("Input Directory Path: [{0}]", folder);


                // System.IO: 244, anything higher throws System.IO.PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
                // AlphaFS  : 255, anything higher throws System.IO.PathTooLongException.
                var subFolder = new string('b', 255);


                var local = Alphaleonis.Win32.Filesystem.Path.Combine(folder, subFolder);
                var unc   = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(local);
                Console.WriteLine("SubFolder length: {0}, total path length: {1}", subFolder.Length, isNetwork ? unc.Length : local.Length);

                // Success.
                var di1 = new Alphaleonis.Win32.Filesystem.DirectoryInfo(isNetwork ? unc : local);

                // Fail.
                //var di1 = new System.IO.DirectoryInfo(local);


                di1.Create();
                Assert.IsTrue(di1.Exists);


                UnitTestConstants.Dump(di1, -17);
            }

            Console.WriteLine();
        }
Beispiel #3
0
        private void DirectoryInfo_MoveTo_Rename(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var newFolderName = "Rename_to_" + tempRoot.RandomDirectoryName;

                var dirInfoAlphaFS = new Alphaleonis.Win32.Filesystem.DirectoryInfo(tempRoot.RandomDirectoryFullPath);

                var dirInfoSystemIO = new System.IO.DirectoryInfo(System.IO.Path.Combine(tempRoot.Directory.FullName, newFolderName));

                Console.WriteLine("Input Directory Path: [{0}]", dirInfoAlphaFS.FullName);
                Console.WriteLine("\n\tRename folder to: [{0}]", dirInfoSystemIO.Name);


                // Create folder.
                dirInfoAlphaFS.Create();


                // Rename folder.
                dirInfoAlphaFS.MoveTo(dirInfoSystemIO.FullName);


                dirInfoAlphaFS.Refresh();
                dirInfoSystemIO.Refresh();


                Assert.IsTrue(dirInfoAlphaFS.Exists, "It is expected that the source exists, but is does not.");

                Assert.AreEqual(dirInfoAlphaFS.Parent.FullName, dirInfoSystemIO.Parent.FullName);
            }

            Console.WriteLine();
        }
Beispiel #4
0
        private void DirectoryInfo_Refresh(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder    = tempRoot.RandomDirectoryFullPath;
                var diSysIo   = new System.IO.DirectoryInfo(folder + "-System.IO");
                var diAlphaFS = new Alphaleonis.Win32.Filesystem.DirectoryInfo(folder + "-AlphaFS");

                Console.WriteLine("System.IO Input Directory Path: [{0}]", diSysIo.FullName);
                Console.WriteLine("AlphaFS   Input Directory Path: [{0}]", diAlphaFS.FullName);


                var existsSysIo = diSysIo.Exists;
                var exists      = diAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsFalse(exists, "The directory exists, but is expected not to.");


                diSysIo.Create();
                diAlphaFS.Create();
                existsSysIo = diSysIo.Exists;
                exists      = diAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsFalse(exists, "The directory exists, but is expected not to.");


                diSysIo.Refresh();
                diAlphaFS.Refresh();
                existsSysIo = diSysIo.Exists;
                exists      = diAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsTrue(exists, "The directory does not exists, but is expected to.");


                diSysIo.Delete();
                diAlphaFS.Delete();
                existsSysIo = diSysIo.Exists;
                exists      = diAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsTrue(exists, "The directory does not exists, but is expected to.");


                diSysIo.Refresh();
                diAlphaFS.Refresh();
                existsSysIo = diSysIo.Exists;
                exists      = diAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsFalse(exists, "The directory exists, but is expected not to.");
            }

            Console.WriteLine();
        }
Beispiel #5
0
        private void DirectoryInfo_Attributes(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = System.IO.Path.GetTempPath();

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }


            using (var rootDir = new TemporaryDirectory(tempPath, MethodBase.GetCurrentMethod().Name))
            {
                var folder  = rootDir.RandomDirectoryFullPath;
                var dirInfo = new Alphaleonis.Win32.Filesystem.DirectoryInfo(folder + "-AlphaFS");

                Console.WriteLine("\nAlphaFS Input Directory Path: [{0}]", dirInfo.FullName);

                dirInfo.Create();


                dirInfo.Attributes |= System.IO.FileAttributes.ReadOnly;
                Assert.IsTrue((dirInfo.Attributes & System.IO.FileAttributes.ReadOnly) != 0, "The directory is not ReadOnly, but is expected to.");

                dirInfo.Attributes &= ~System.IO.FileAttributes.ReadOnly;
                Assert.IsTrue((dirInfo.Attributes & System.IO.FileAttributes.ReadOnly) == 0, "The directory is ReadOnly, but is expected not to.");


                dirInfo.Attributes |= System.IO.FileAttributes.Hidden;
                Assert.IsTrue((dirInfo.Attributes & System.IO.FileAttributes.Hidden) != 0, "The directory is not Hidden, but is expected to.");

                dirInfo.Attributes &= ~System.IO.FileAttributes.Hidden;
                Assert.IsTrue((dirInfo.Attributes & System.IO.FileAttributes.Hidden) == 0, "The directory is Hidden, but is expected not to.");


                dirInfo.Attributes |= System.IO.FileAttributes.System;
                Assert.IsTrue((dirInfo.Attributes & System.IO.FileAttributes.System) != 0, "The directory is not System, but is expected to.");

                dirInfo.Attributes &= ~System.IO.FileAttributes.System;
                Assert.IsTrue((dirInfo.Attributes & System.IO.FileAttributes.System) == 0, "The directory is System, but is expected not to.");
            }

            Console.WriteLine();
        }
Beispiel #6
0
        public static void SaveCache(ConcurrentDictionary <int, CachedSeriesInfo> series, ConcurrentDictionary <int, CachedMovieInfo> movies, [NotNull] FileInfo cacheFile, long timestamp)
        {
            DirectoryInfo di = cacheFile.Directory;

            if (!di.Exists)
            {
                di.Create();
            }

            Logger.Info("Saving Cache to: {0}", cacheFile.FullName);
            try
            {
                RotateCacheFiles(cacheFile);

                // write ourselves to disc for next time.  use same structure as thetvdb.com (limited fields, though)
                // to make loading easy
                XmlWriterSettings settings = new XmlWriterSettings
                {
                    Indent = true,
                    NewLineOnAttributes = true
                };

                using (XmlWriter writer = XmlWriter.Create(cacheFile.FullName, settings))
                {
                    writer.WriteStartDocument();
                    writer.WriteStartElement("Data");
                    writer.WriteAttributeToXml("time", timestamp);

                    foreach (KeyValuePair <int, CachedSeriesInfo> kvp in series)
                    {
                        if (kvp.Value.SrvLastUpdated != 0)
                        {
                            kvp.Value.WriteXml(writer);
                            foreach (Episode e in kvp.Value.Episodes)
                            {
                                e.WriteXml(writer);
                            }
                        }
                        else
                        {
                            Logger.Info($"Cannot save {kvp.Value.TvdbCode} ({kvp.Value.Name}) as it has not been updated at all.");
                        }
                    }

                    //
                    // <BannersCache>
                    //      <BannersItem>
                    //          <SeriesId>123</SeriesId>
                    //          <Banners>
                    //              <Banner>

                    writer.WriteStartElement("BannersCache");

                    foreach (KeyValuePair <int, CachedSeriesInfo> kvp in series)
                    {
                        writer.WriteStartElement("BannersItem");

                        writer.WriteElement("SeriesId", kvp.Key);

                        writer.WriteStartElement("Banners");

                        //We need to write out all banners that we have in any of the collections.

                        foreach (Banner ban in kvp.Value.AllBanners.Select(kvp3 => kvp3.Value))
                        {
                            ban.WriteXml(writer);
                        }

                        writer.WriteEndElement(); //Banners
                        writer.WriteEndElement(); //BannersItem
                    }

                    writer.WriteEndElement(); // BannersCache

                    foreach (KeyValuePair <int, CachedMovieInfo> kvp in movies)
                    {
                        if (!kvp.Value.IsSearchResultOnly)
                        {
                            kvp.Value.WriteXml(writer);
                        }
                        else
                        {
                            Logger.Info($"Cannot save {kvp.Value.TvdbCode} ({kvp.Value.Name}) as it is a search result that has not been used.");
                        }
                    }

                    // TODO SAVE MIE BANNERS if we ever have them
                    // <BannersCache>
                    //      <BannersItem>
                    //          <SeriesId>123</SeriesId>
                    //          <Banners>
                    //              <Banner>

                    /*writer.WriteStartElement("BannersCache");
                    *
                    *  foreach (KeyValuePair<int, CachedSeriesInfo> kvp in series)
                    *  {
                    *   writer.WriteStartElement("BannersItem");
                    *
                    *   writer.WriteElement("SeriesId", kvp.Key);
                    *
                    *   writer.WriteStartElement("Banners");
                    *
                    *   //We need to write out all banners that we have in any of the collections.
                    *
                    *   foreach (Banner ban in kvp.Value.AllBanners.Select(kvp3 => kvp3.Value))
                    *   {
                    *       ban.WriteXml(writer);
                    *   }
                    *
                    *   writer.WriteEndElement(); //Banners
                    *   writer.WriteEndElement(); //BannersItem
                    *  }
                    *
                    *  writer.WriteEndElement(); // BannersCache*/

                    writer.WriteEndElement(); // data

                    writer.WriteEndDocument();
                }
            }
            catch (Exception e)
            {
                Logger.Error(e, $"Failed to save Cache to {cacheFile.FullName}");
            }
        }
Beispiel #7
0
        private void AlphaFS_Directory_EnumerateAlternateDataStreams(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = tempRoot.RandomDirectoryFullPath;

                Console.WriteLine("Input Directory Path: [{0}]", folder);


                var myStream            = "ӍƔŞtrëƛɱ-" + tempRoot.RandomString;
                var myStream2           = "myStreamTWO-" + tempRoot.RandomString;
                var allStreams          = new[] { myStream, myStream2 };
                var streamStringContent = "(1) Computer: [" + Environment.MachineName + "]" + "\tHello there, " + Environment.UserName;

                Console.WriteLine("\nA directory is created and {0} streams are added.", allStreams.Length.ToString(CultureInfo.CurrentCulture));

                var di = new Alphaleonis.Win32.Filesystem.DirectoryInfo(folder);
                di.Create();


                const int defaultStreamsDirectory = 0; // The default number of data streams for a folder.
                var       currentNumberofStreams  = di.EnumerateAlternateDataStreams().Count();

                Assert.AreEqual(defaultStreamsDirectory, currentNumberofStreams, "Total amount of default streams do not match.");
                Assert.AreEqual(currentNumberofStreams, Alphaleonis.Win32.Filesystem.Directory.EnumerateAlternateDataStreams(folder).Count(), "Total amount of Directory.EnumerateAlternateDataStreams() streams do not match.");


                // Create alternate data streams.
                // Because of the colon, you must supply a full path and use PathFormat.FullPath or PathFormat.LongFullPath,
                // to prevent a: "NotSupportedException: path is in an invalid format." exception.

                var stream1Name = folder + Alphaleonis.Win32.Filesystem.Path.StreamSeparator + myStream;
                var stream2Name = folder + Alphaleonis.Win32.Filesystem.Path.StreamSeparator + myStream2;

                Alphaleonis.Win32.Filesystem.File.WriteAllLines(stream1Name, UnitTestConstants.StreamArrayContent, Alphaleonis.Win32.Filesystem.PathFormat.FullPath);
                Alphaleonis.Win32.Filesystem.File.WriteAllText(stream2Name, streamStringContent, Alphaleonis.Win32.Filesystem.PathFormat.FullPath);



                var newNumberofStreams = Alphaleonis.Win32.Filesystem.Directory.EnumerateAlternateDataStreams(folder).Count();
                Console.WriteLine("\n\nNew stream count: [{0}]", newNumberofStreams);


                // Enumerate all streams from the folder.
                foreach (var stream in di.EnumerateAlternateDataStreams())
                {
                    Assert.IsTrue(UnitTestConstants.Dump(stream, -10));
                }


                // Show the contents of our streams.
                Console.WriteLine();
                foreach (var streamName in allStreams)
                {
                    Console.WriteLine("\n\tStream name: [{0}]", streamName);


                    // Because of the colon, you must supply a full path and use PathFormat.FullPath or PathFormat.LongFullPath,
                    // to prevent a: "NotSupportedException: path is in an invalid format." exception.

                    foreach (var line in Alphaleonis.Win32.Filesystem.File.ReadAllLines(folder + Alphaleonis.Win32.Filesystem.Path.StreamSeparator + streamName, Alphaleonis.Win32.Filesystem.PathFormat.FullPath))
                    {
                        Console.WriteLine("\t\t{0}", line);
                    }
                }



                // Show DirectoryInfo instance data of the streams.

                var dirInfo = new Alphaleonis.Win32.Filesystem.DirectoryInfo(stream1Name, Alphaleonis.Win32.Filesystem.PathFormat.LongFullPath);

                Console.WriteLine();
                UnitTestConstants.Dump(dirInfo, -17);



                // Show FileInfo instance data of the streams.

                var fileInfo1 = new Alphaleonis.Win32.Filesystem.FileInfo(stream1Name, Alphaleonis.Win32.Filesystem.PathFormat.LongFullPath);
                var fileInfo2 = new Alphaleonis.Win32.Filesystem.FileInfo(stream2Name, Alphaleonis.Win32.Filesystem.PathFormat.LongFullPath);

                Console.WriteLine();
                UnitTestConstants.Dump(fileInfo1, -17);
                UnitTestConstants.Dump(fileInfo2, -17);


                Assert.AreEqual(myStream, fileInfo1.Name);
                Assert.AreEqual(myStream2, fileInfo2.Name);

                Assert.IsNull(fileInfo1.EntryInfo);
                Assert.IsNull(fileInfo2.EntryInfo);
            }

            Console.WriteLine();
        }
 public override void Create()
 {
     instance.Create();
 }
Beispiel #9
0
        private void DirectoryInfo_Refresh(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = System.IO.Path.GetTempPath();

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }


            using (var rootDir = new TemporaryDirectory(tempPath, "DirectoryInfo.Refresh"))
            {
                var folder    = rootDir.RandomFileFullPath;
                var diSysIo   = new System.IO.DirectoryInfo(folder + "-System.IO");
                var diAlphaFS = new Alphaleonis.Win32.Filesystem.DirectoryInfo(folder + "-AlphaFS");

                Console.WriteLine("\nSystem.IO Input Directory Path: [{0}]", diSysIo.FullName);
                Console.WriteLine("AlphaFS   Input Directory Path: [{0}]", diAlphaFS.FullName);


                var existsSysIo = diSysIo.Exists;
                var exists      = diAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsFalse(exists, "The directory exists, but is expected not to.");


                diSysIo.Create();
                diAlphaFS.Create();
                existsSysIo = diSysIo.Exists;
                exists      = diAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsFalse(exists, "The directory exists, but is expected not to.");


                diSysIo.Refresh();
                diAlphaFS.Refresh();
                existsSysIo = diSysIo.Exists;
                exists      = diAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsTrue(exists, "The directory does not exists, but is expected to.");


                diSysIo.Delete();
                diAlphaFS.Delete();
                existsSysIo = diSysIo.Exists;
                exists      = diAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsTrue(exists, "The directory does not exists, but is expected to.");


                diSysIo.Refresh();
                diAlphaFS.Refresh();
                existsSysIo = diSysIo.Exists;
                exists      = diAlphaFS.Exists;
                Assert.AreEqual(existsSysIo, exists);
                Assert.IsFalse(exists, "The directory exists, but is expected not to.");
            }

            Console.WriteLine();
        }
        private void Directory_EnumerateAlternateDataStreams(bool isNetwork)
        {
            UnitTestConstants.PrintUnitTestHeader(isNetwork);

            var tempPath = Alphaleonis.Win32.Filesystem.Path.GetTempPath("Directory-EnumerateAlternateDataStreams-" + UnitTestConstants.GetRandomFileNameWithDiacriticCharacters());

            if (isNetwork)
            {
                tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);
            }

            const int defaultStreamsDirectory = 0; // The default number of data streams for a folder.

            Console.WriteLine("\nInput Directory Path: [{0}]", tempPath);
            Console.WriteLine("\nA directory is created and {0} streams are added.", UnitTestConstants.AllStreams.Count());


            try
            {
                var di = new Alphaleonis.Win32.Filesystem.DirectoryInfo(tempPath);
                di.Create();

                var currentNumberofStreams = di.EnumerateAlternateDataStreams().Count();

                Assert.AreEqual(defaultStreamsDirectory, currentNumberofStreams, "Total amount of default streams do not match.");
                Assert.AreEqual(currentNumberofStreams, Alphaleonis.Win32.Filesystem.Directory.EnumerateAlternateDataStreams(tempPath).Count(), "Total amount of Directory.EnumerateAlternateDataStreams() streams do not match.");


                // Create alternate data streams.
                // Because of the colon, you must supply a full path and use PathFormat.FullPath or PathFormat.LongFullPath,
                // to prevent a: "NotSupportedException: path is in an invalid format." exception.

                Alphaleonis.Win32.Filesystem.File.WriteAllLines(tempPath + Alphaleonis.Win32.Filesystem.Path.StreamSeparator + UnitTestConstants.MyStream, UnitTestConstants.StreamArrayContent, Alphaleonis.Win32.Filesystem.PathFormat.FullPath);
                Alphaleonis.Win32.Filesystem.File.WriteAllText(tempPath + Alphaleonis.Win32.Filesystem.Path.StreamSeparator + UnitTestConstants.MyStream2, UnitTestConstants.StreamStringContent, Alphaleonis.Win32.Filesystem.PathFormat.FullPath);


                var newNumberofStreams = Alphaleonis.Win32.Filesystem.Directory.EnumerateAlternateDataStreams(tempPath).Count();
                Console.WriteLine("\n\nCurrent stream Count(): [{0}]", newNumberofStreams);


                // Enumerate all streams from the folder.
                foreach (var stream in di.EnumerateAlternateDataStreams())
                {
                    Assert.IsTrue(UnitTestConstants.Dump(stream, -10));
                }


                // Show the contents of our streams.
                Console.WriteLine();
                foreach (var streamName in UnitTestConstants.AllStreams)
                {
                    Console.WriteLine("\n\tStream name: [{0}]", streamName);

                    // Because of the colon, you must supply a full path and use PathFormat.FullPath or PathFormat.LongFullPath,
                    // to prevent a: "NotSupportedException: path is in an invalid format." exception.

                    foreach (var line in Alphaleonis.Win32.Filesystem.File.ReadAllLines(tempPath + Alphaleonis.Win32.Filesystem.Path.StreamSeparator + streamName, Alphaleonis.Win32.Filesystem.PathFormat.FullPath))
                    {
                        Console.WriteLine("\t\t{0}", line);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\n\tCaught (UNEXPECTED) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, "  "));
                Assert.IsTrue(false);
            }
            finally
            {
                Alphaleonis.Win32.Filesystem.Directory.Delete(tempPath);
                Assert.IsFalse(Alphaleonis.Win32.Filesystem.Directory.Exists(tempPath), "Cleanup failed: Directory should have been removed.");
            }

            Console.WriteLine();
        }
        public static int CopyTo(this DirectoryInfo sourceDirectory, DirectoryInfo destinationDirectory,
                                  bool copySubDirectories = true, IEnumerable<Predicate<FileInfo>> filesToExclude = null, IEnumerable<string> directoriesToExclude = null)
        {
            var copiedItems = 0;

            if (sourceDirectory == null)
            {
                throw new ArgumentNullException(nameof(sourceDirectory));
            }

            if (destinationDirectory == null)
            {
                throw new ArgumentNullException(nameof(destinationDirectory));
            }

            if (!sourceDirectory.Exists)
            {
                throw new DirectoryNotFoundException(
                    $"Source directory does not exist or could not be found: {sourceDirectory.FullName}");
            }

            var filePredicates = filesToExclude ?? new List<Predicate<FileInfo>>();
            var excludedDirectories = directoriesToExclude ?? new List<string>();

            if (destinationDirectory.Exists)
            {
                if (!destinationDirectory.IsEmpty())
                {
                    var fileCount = destinationDirectory.GetFiles().Length;
                    var directoryCount = destinationDirectory.GetDirectories().Length;
                    throw new IOException(
                        $"The folder '{destinationDirectory.FullName}' cannot be used as a target folder since there are {fileCount} files and {directoryCount} folders in the folder");
                }
            }
            else
            {
                destinationDirectory.Create();
                copiedItems++;
            }

            var files = sourceDirectory.EnumerateFiles().Where(file => filePredicates.All(predicate => !predicate(file))).ToList();

            foreach (FileInfo file in files)
            {
                var temppath = Path.Combine(destinationDirectory.FullName, file.Name);
                Debug.WriteLine($"Copying file '{file.Name}' to '{temppath.FullName}'");
                file.CopyTo(temppath.FullName, false);
                copiedItems++;
            }

            if (copySubDirectories)
            {
                DirectoryInfo[] subDirectory = sourceDirectory.GetDirectories();

                foreach (DirectoryInfo subdir in subDirectory)
                {
                    if (
                        !excludedDirectories.Any(
                            excluded => subdir.Name.Equals(excluded, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        var subDirectoryTempPath = Path.Combine(destinationDirectory.FullName, subdir.Name);

                        var subDirectoryInfo = new DirectoryInfo(subDirectoryTempPath.FullName);

                        Debug.WriteLine($"Copying directory '{subDirectoryInfo.Name}' to '{subDirectoryTempPath.FullName}'");

                        copiedItems += subdir.CopyTo(subDirectoryInfo, copySubDirectories, filesToExclude, directoriesToExclude);
                    }
                }
            }
            return copiedItems;
        }