Example #1
0
        public void TestToString()
        {
            var a = new ZlpDirectoryInfo(@"C:\ablage\test.txt");
            var b = new DirectoryInfo(@"C:\ablage\test.txt");

            var x = a.ToString();
            var y = b.ToString();

            Assert.AreEqual(x, y);

            // --

            a = new ZlpDirectoryInfo(@"C:\ablage\");
            b = new DirectoryInfo(@"C:\ablage\");

            x = a.ToString();
            y = b.ToString();

            Assert.AreEqual(x, y);

            // --

            a = new ZlpDirectoryInfo(@"test.txt");
            b = new DirectoryInfo(@"test.txt");

            x = a.ToString();
            y = b.ToString();

            Assert.AreEqual(x, y);

            // --

            a = new ZlpDirectoryInfo(@"c:\ablage\..\ablage\test.txt");
            b = new DirectoryInfo(@"c:\ablage\..\ablage\test.txt");

            x = a.ToString();
            y = b.ToString();

            Assert.AreEqual(x, y);

            // --

            a = new ZlpDirectoryInfo(@"\ablage\test.txt");
            b = new DirectoryInfo(@"\ablage\test.txt");

            x = a.ToString();
            y = b.ToString();

            Assert.AreEqual(x, y);

            // --

            a = new ZlpDirectoryInfo(@"ablage\test.txt");
            b = new DirectoryInfo(@"ablage\test.txt");

            x = a.ToString();
            y = b.ToString();

            Assert.AreEqual(x, y);
        }
Example #2
0
        public void TestTilde()
        {
            // https://github.com/UweKeim/ZetaLongPaths/issues/24

            var path1 = ZlpDirectoryInfo.GetTemp().CombineDirectory(Guid.NewGuid().ToString()).CheckCreate();
            var path2 = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));

            try
            {
                var p1 = path1.CombineDirectory(@"a~b").CheckCreate();
                var p2 = Directory.CreateDirectory(Path.Combine(path2.FullName, @"a~b")).FullName;

                var f1 = p1.CombineFile("1.txt");
                f1.WriteAllText("1");

                var f2 = Path.Combine(p2, "1.txt");
                File.WriteAllText(f2, "1");

                foreach (var file in p1.GetFiles())
                {
                    Console.WriteLine(file.FullName);
                }

                foreach (var file in Directory.GetFiles(p2))
                {
                    Console.WriteLine(file);
                }
            }
            finally
            {
                path1.SafeDelete();
                path2.Delete(true);
            }
        }
Example #3
0
        public void TestGetFileSystemInfos()
        {
            var path = ZlpDirectoryInfo.GetTemp().CombineDirectory(Guid.NewGuid().ToString()).CheckCreate();

            try
            {
                var p1 = path.CombineDirectory(@"a").CheckCreate();
                path.CombineDirectory(@"b").CheckCreate();

                var f1 = p1.CombineFile("1.txt");
                f1.WriteAllText("1");

                Assert.IsTrue(path.GetFileSystemInfos().Length == 2);
                Assert.IsTrue(path.GetFileSystemInfos(SearchOption.AllDirectories).Length == 3);
                Assert.IsTrue(
                    path.GetFileSystemInfos(SearchOption.AllDirectories).Where(f => f is ZlpFileInfo).ToList().Count ==
                    1);
                Assert.IsTrue(
                    path.GetFileSystemInfos(SearchOption.AllDirectories)
                    .Where(f => f is ZlpDirectoryInfo)
                    .ToList()
                    .Count == 2);
            }
            finally
            {
                path.SafeDelete();
            }
        }
        public static void Main(string[] args)
        {
            string ModuleLocation = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string dataJson       = Path.Combine(ModuleLocation, "data.json");

            string     dataContent = File.ReadAllText(Path.Combine(ModuleLocation, "data.json"));
            Rootobject canconvert  = JsonConvert.DeserializeObject <Rootobject>(dataContent);

            Console.WriteLine("it can convert");

            var           HierarchyPath  = new ZlpDirectoryInfo(@"D:\EsriBitBucket\wa-woodside\RestEndPoints\AuthApi\Esri.WinAuthApi.FW\Views\Shared");
            List <string> PathListToFind = new List <string>();

            //string HierarchyPath = DirectoryPath;

            while (!HierarchyPath.FullName.Equals(@"D:\EsriBitBucket", StringComparison.OrdinalIgnoreCase))
            {
                PathListToFind.Add(HierarchyPath.FullName);
                HierarchyPath = HierarchyPath.Parent;
                Console.WriteLine(HierarchyPath.FullName);
            }
            //foreach (var filePath in folderPath.GetFiles())
            //{
            //    Console.Write("File {0} has a size of {1}",
            //        filePath.FullName,
            //        filePath.Length);
            //}

            Console.ReadLine();
        }
Example #5
0
        public static void DeleteFolderUsingZetaLongPaths(string path, bool recursive = true)
        {
            ZetaLongPaths.ZlpDirectoryInfo di = new ZlpDirectoryInfo(path);
            // Delete all files and sub-folders?
            if (recursive)
            {
                // Yep... Let's do this
                var subfolders = di.GetDirectories(path);
                foreach (var s in subfolders)
                {
                    DeleteFolderUsingZetaLongPaths(s.FullName, recursive);
                }
            }

            // Get all files of the folder
            var files = di.GetFiles(path);

            foreach (var f in files)
            {
                RemoveReadOnlyAttributeIfExistsUsingZetaLongPaths(path);

                // Delete the file
                f.Delete();
            }

            // When we get here, all the files of the folder were
            // already deleted, so we just delete the empty folder
            di.Delete(true);            //TODO: should recursive simply be used? can it handle read-only items?
        }
Example #6
0
        internal static void CopyDirectory(ZlpDirectoryInfo source, ZlpDirectoryInfo destination, bool copySubDirs)
        {
            Assert.DirectoryExists(source);

            if (destination.Exists == false)
            {
                destination.Create();
            }

            ZlpFileInfo[] sourceFiles = source.GetFiles();

            foreach (ZlpFileInfo sourceFile in sourceFiles)
            {
                string destinationFilePath = Path.Combine(destination.FullName, sourceFile.Name);

                sourceFile.CopyTo(destinationFilePath, false);
            }

            if (copySubDirs)
            {
                ZlpDirectoryInfo[] sourceDirectories = source.GetDirectories();

                foreach (ZlpDirectoryInfo sourceDirectory in sourceDirectories)
                {
                    string destinationDirectoryPath = Path.Combine(destination.FullName, sourceDirectory.Name);

                    ZlpDirectoryInfo destinationDirectory = new ZlpDirectoryInfo(destinationDirectoryPath);

                    FileSystemUtil.CopyDirectory(sourceDirectory, destinationDirectory, copySubDirs);
                }
            }
        }
Example #7
0
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            Regex  re     = new Regex(@"^(?:[\w]\:|\\)(\\[a-z_\-\s0-9\.]+)*\\?$", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
            string strVal = (value ?? "").ToString();
            var    valid  = re.IsMatch(strVal) ? new ValidationResult(true, null) : new ValidationResult(false, Properties.Resources.WrongPathFormat);

            // IF VALID PATH CHECK IF EXISTS
            if (valid.IsValid)
            {
                // CHECK IF THE PATH IS FOR A FILE OR A DIRECTORY
                var fileInfo = new ZlpFileInfo(strVal);
                var attrs    = fileInfo.Attributes;
                if ((attrs & ZetaLongPaths.Native.FileAttributes.Directory) == ZetaLongPaths.Native.FileAttributes.Directory)
                {
                    var dirInfo = new ZlpDirectoryInfo(strVal);
                    if (!dirInfo.Exists)
                    {
                        valid = new ValidationResult(false, Properties.Resources.PathNotFound);
                    }
                }
                else
                {
                    if (!fileInfo.Exists)
                    {
                        valid = new ValidationResult(false, Properties.Resources.PathNotFound);
                    }
                }
            }
            return(valid);
        }
        public static void AddDirectory(this ZipArchive archive, ZlpDirectoryInfo directory, IEnumerable <string> whitelistedExtensions, IEnumerable <string> excludePatterns, bool recursive = true)
        {
            Assert.IsNotNull(archive, "An archive must be provided.");

            SearchOption option = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;

            ZlpFileInfo[] files = directory.GetFiles("*", option);

            foreach (ZlpFileInfo file in files)
            {
                if (whitelistedExtensions.Contains(file.Extension))
                {
                    bool skip = (from p in excludePatterns
                                 where file.FullName.Contains(p)
                                 select p).Count() > 0;

                    if (!skip)
                    {
                        string archiveName = file.FullName.Replace(directory.FullName + "\\", string.Empty);

                        archive.CreateEntryFromFile(file.FullName, archiveName, CompressionLevel.Optimal);
                    }
                }
            }
        }
        private void DeleteRedundantFiles(string folderPath)
        {
            var before3HoursDateTime = DateTime.Now.AddHours(-CachedParams.HourNumber);
            var directoryInfo        = new ZlpDirectoryInfo(folderPath);
            var fileInfoes           = directoryInfo.GetFiles("*.*", SearchOption.AllDirectories);

            foreach (var zlpFileInfo in fileInfoes)
            {
                Trace.Write(zlpFileInfo.LastAccessTime);
                if (zlpFileInfo.LastAccessTime >= before3HoursDateTime)
                {
                    continue;
                }
                try
                {
#if !DEBUG
                    zlpFileInfo.Delete();
#endif
                }
                catch (Exception e)
                {
                    Trace.Write(e.GetExceptionMessages());
                }
            }
        }
Example #10
0
        public void PhanLoaiBonHuHuVipProDepTraiKuTePhoMaiQue()
        {
            string           input  = File.ReadAllText(Environment.CurrentDirectory + "\\input.txt");
            ZlpDirectoryInfo folder = new ZlpDirectoryInfo(input);
            string           s      = "";

            foreach (ZlpDirectoryInfo itemFolder in folder.GetDirectories())
            {
                foreach (ZlpDirectoryInfo item in itemFolder.GetDirectories())
                {
                    if (item.Name.ToLower().Contains("shir"))
                    {
                        s += (item.Name) + Environment.NewLine;
                    }
                    // string name = item.Name.Replace("T Shirt", "");
                    //try
                    //{
                    //    if (item.Name.ToLower().Contains("shirt"))
                    //    {
                    //        item.Delete(true);
                    //    }
                    //    item.MoveTo(itemFolder.GetFullPath() + "/" + StringToString(name));
                    //}
                    //catch
                    //{
                    //    item.MoveTo(itemFolder.GetFullPath() + "/" + StringToString(name) + " " + new Random().Next(0, 100));

                    //}
                }
            }
        }
Example #11
0
        public void TestCreateWithLimitedPermission()
        {
            // Only in development environment.
            if (Directory.Exists(@"\\nas001\Data\users\ukeim\Ablage\restricted\"))
            {
                if (true)
                {
                    ZlpIOHelper.DeleteDirectoryContents(@"\\nas001\Data\users\ukeim\Ablage\restricted\", true);

                    var dirInfo1 = new ZlpDirectoryInfo(@"\\nas001\Data\users\ukeim\Ablage\restricted\my\folder");

                    // Der Benutzer hat keine Rechte, um "restricted" zu erstellen, nur darin enthaltene.
                    using (new ZlpImpersonator(@"small_user", @"office", @"ThisIsAnUnsecurePassword"))
                    {
                        Assert.DoesNotThrow(delegate { new DirectoryInfo(dirInfo1.FullName).Create(); });
                    }
                }
                if (true)
                {
                    ZlpIOHelper.DeleteDirectoryContents(@"\\nas001\Data\users\ukeim\Ablage\restricted\", true);

                    var dirInfo1 = new ZlpDirectoryInfo(@"\\nas001\Data\users\ukeim\Ablage\restricted\my\folder");

                    // Der Benutzer hat keine Rechte, um "restricted" zu erstellen, nur darin enthaltene.
                    using (new ZlpImpersonator(@"small_user", @"office", @"ThisIsAnUnsecurePassword"))
                    {
                        Assert.DoesNotThrow(delegate { dirInfo1.Create(); });
                    }
                }
            }
        }
 public ZlpFileOrDirectoryInfo(
     // ReSharper disable SuggestBaseTypeForParameter
     ZlpDirectoryInfo info)
 // ReSharper restore SuggestBaseTypeForParameter
 {
     _preferedType = PreferedType.Directory;
     FullName      = info.FullName;
     OriginalPath  = info.ToString();
 }
Example #13
0
        /// <summary>
        /// Checks and creates the folder if not yet exists.
        /// </summary>
        /// <param name="folderPath">The folder path.</param>
        /// <returns></returns>
        public static ZlpDirectoryInfo CheckCreateFolder(
            ZlpDirectoryInfo folderPath)
        {
            if (folderPath != null && !folderPath.Exists)
            {
                folderPath.Create();
            }

            return(folderPath);
        }
Example #14
0
        private void CreateAllNotExistingFolder(ZlpDirectoryInfo directories)
        {
            if (directories.Exists)
            {
                return;
            }

            this.CreateAllNotExistingFolder(directories.Parent);
            Microsoft.Experimental.IO.LongPathDirectory.Create(directories.FullName);
        }
Example #15
0
        public long DirSize(ZlpDirectoryInfo d)
        {
            // Add file sizes.
            var fis  = d.GetFiles();
            var size = fis.Sum(fi => fi.Length);
            // Add subdirectory sizes.
            var dis = d.GetDirectories();

            size += dis.Sum(di => DirSize(di));
            return(size);
        }
Example #16
0
        public void TestGeneral()
        {
            //Assert.IsTrue(new ZlpDirectoryInfo(Path.GetTempPath()).CreationTime>DateTime.MinValue);
            //Assert.IsTrue(new ZlpDirectoryInfo(Path.GetTempPath()).Exists);
            //Assert.IsFalse(new ZlpDirectoryInfo(@"C:\Ablage\doesnotexistjdlkfjsdlkfj").Exists);
            //Assert.IsTrue(new ZlpDirectoryInfo(Path.GetTempPath()).Exists);
            //Assert.IsFalse(new ZlpDirectoryInfo(@"C:\Ablage\doesnotexistjdlkfjsdlkfj2").Exists);
            //Assert.IsFalse(new ZlpDirectoryInfo(@"\\zetac11\C$\Ablage").Exists);
            //Assert.IsFalse(new ZlpDirectoryInfo(@"\\zetac11\C$\Ablage\doesnotexistjdlkfjsdlkfj2").Exists);

            const string s1 = @"C:\Users\Chris\Documents\Development\ADC\InterStore.NET\Visual Studio 2008\6.4.2\Zeta Resource Editor";
            const string s2 = @"C:\Users\Chris\Documents\Development\ADC\InterStore.NET\Visual Studio 2008\6.4.2\Web\central\Controls\App_LocalResources\ItemSearch";

            var s3 = ZlpPathHelper.GetRelativePath(s1, s2);

            Assert.AreEqual(s3, @"..\Web\central\Controls\App_LocalResources\ItemSearch");

            var ext = ZlpPathHelper.GetExtension(s3);

            Assert.IsNullOrEmpty(ext);

            ext = ZlpPathHelper.GetExtension(@"C:\Ablage\Uwe.txt");
            Assert.AreEqual(ext, @".txt");

            const string path = @"C:\Ablage\Test";

            Assert.AreEqual(
                new DirectoryInfo(path).Name,
                new ZlpDirectoryInfo(path).Name);

            Assert.AreEqual(
                new DirectoryInfo(path).FullName,
                new ZlpDirectoryInfo(path).FullName);

            const string filePath = @"C:\Ablage\Test\file.txt";
            var          fn1      = new FileInfo(filePath).Directory.FullName;
            var          fn2      = new ZlpFileInfo(filePath).Directory.FullName;

            var fn1a = new FileInfo(filePath).DirectoryName;
            var fn2a = new ZlpFileInfo(filePath).DirectoryName;

            Assert.AreEqual(fn1, fn2);
            Assert.AreEqual(fn1a, fn2a);

            var fn = new ZlpDirectoryInfo(@"\\zetac11\C$\Ablage\doesnotexistjdlkfjsdlkfj2").Parent.FullName;

            Assert.AreEqual(fn, @"\\zetac11\C$\Ablage");

            fn = new ZlpDirectoryInfo(@"\\zetac11\C$\Ablage\doesnotexistjdlkfjsdlkfj2\").Parent.FullName;

            Assert.AreEqual(fn, @"\\zetac11\C$\Ablage");
        }
Example #17
0
 private IEnumerable <FileJob> GetFiles(string f, string source, string target)
 {
     if (ZlpIOHelper.DirectoryExists(f))
     {
         ZlpDirectoryInfo dir = new ZlpDirectoryInfo(f);
         foreach (var item in GetFiles(dir, source, target))
         {
             yield return(item);
         }
     }
     else if (ZlpIOHelper.FileExists(f))
     {
         ZlpFileInfo file = new ZlpFileInfo(f);
         yield return(new FileJob(file, new ZlpFileInfo(replacedir(f, source, target)), copyType, CheckCancel));
     }
 }
Example #18
0
        private IEnumerable <FileJob> GetFiles(ZlpDirectoryInfo dir, string source, string target)
        {
            yield return(new FileJob(dir, new ZlpDirectoryInfo(replacedir(dir.FullName, source, target)), copyType, CheckCancel));

            foreach (var file in dir.GetFiles())
            {
                yield return(new FileJob(file, new ZlpFileInfo(replacedir(file.FullName, source, target)), copyType, CheckCancel));
            }
            foreach (var subdir in dir.GetDirectories())
            {
                foreach (var item in GetFiles(subdir, source, target))
                {
                    yield return(item);
                }
            }
        }
Example #19
0
        public void ConstructTreeDfs(Folder dir)
        {
            var directory = new ZlpDirectoryInfo(dir.Name);

            if (directory.Exists)
            {
                ZlpDirectoryInfo[] childDirs;
                try
                {
                    childDirs = directory.GetDirectories();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return;
                }

                var childFolders = new Folder[childDirs.Length];
                for (var i = 0; i < childDirs.Length; i++)
                {
                    childFolders[i] = new Folder(childDirs[i].FullName);
                }
                dir.AddChildFolders(childFolders);

                var files = directory.GetFiles();
                var f     = new File[files.Length];
                for (var i = 0; i < files.Length; i++)
                {
                    try
                    {
                        f[i] = new File(files[i].FullName, files[i].Length);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                dir.AddFiles(f);
                if (DeepWalk)
                {
                    foreach (var item in childFolders)
                    {
                        ConstructTreeDfs(item);
                    }
                }
            }
        }
Example #20
0
        public void Execute(BuildRequest request, ZlpDirectoryInfo workingDirectory)
        {
            // https://docs.aws.amazon.com/codedeploy/latest/userguide/writing-app-spec.html
            try
            {
                ZlpFileInfo appSpecFile = (from f in workingDirectory.GetFiles("appspec.yml", SearchOption.TopDirectoryOnly)
                                           select f).SingleOrDefault();

                if (appSpecFile == null)
                {
                    Program.Logger.Warn("Generating AppSpec file. For advanced configuration create and include an appspec.yml at the root of your project. See: https://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref-structure.html");

                    string appSpecFilePath = Path.Combine(workingDirectory.FullName, "appspec.yml");

                    appSpecFile = new ZlpFileInfo(appSpecFilePath);

                    AppSpec appSpec = this.BuildAppSpec(request, workingDirectory);

                    using (FileStream stream = appSpecFile.OpenCreate())
                    {
                        using (StreamWriter sWriter = new StreamWriter(stream))
                        {
                            using (StringWriter writer = new StringWriter())
                            {
                                YamlDotNet.Serialization.Serializer serializer = new YamlDotNet.Serialization.Serializer();
                                serializer.Serialize(writer, appSpec);
                                var yaml = writer.ToString();
                                sWriter.WriteLine(yaml);
                                Program.Logger.Info("----------------------- BEGIN APPSPEC -----------------------");
                                Program.Logger.Info(yaml);
                                Program.Logger.Info("----------------------- END APPSPEC -----------------------");
                            }
                        }
                    }
                }
                else
                {
                    Program.Logger.Info("    An AppSpec file was found in the working directory. This plug-in will not generate an AppSec.");
                }
            }
            catch (Exception ex)
            {
                Program.Logger.Error(ex);
                throw ex;
            }
        }
Example #21
0
 static long DirSize(ZlpDirectoryInfo d)
 {
     long size = 0;
     // Add file sizes.
     ZlpFileInfo[] fis = d.GetFiles();
     foreach (ZlpFileInfo fi in fis)
     {
         size += fi.Length;
     }
     // Add subdirectory sizes.
     ZlpDirectoryInfo[] dis = d.GetDirectories();
     foreach (ZlpDirectoryInfo di in dis)
     {
         size += DirSize(di);
     }
     return size;
 }
Example #22
0
 private void FindEmptyFilesRecursive(ZlpDirectoryInfo Dir, List <string> emptyfiles)
 {
     if (IsCancelled)
     {
         return;
     }
     foreach (var subdir in Dir.GetDirectories())
     {
         FindEmptyFilesRecursive(subdir, emptyfiles);
     }
     foreach (var file in Dir.GetFiles())
     {
         if (file.Length == 0)
         {
             emptyfiles.Add(file.FullName);
         }
     }
 }
Example #23
0
        private bool FindEmptyDirsRecursive(ZlpDirectoryInfo Dir, List <string> emptydirs)
        {
            if (IsCancelled)
            {
                return(false);
            }
            var empty = true;

            foreach (var subdir in Dir.GetDirectories())
            {
                empty &= FindEmptyDirsRecursive(subdir, emptydirs);
            }
            if (empty && Dir.GetFiles().Length == 0)
            {
                emptydirs.Add(Dir.FullName);
                return(true);
            }
            return(false);
        }
Example #24
0
        public void TestMove()
        {
            var path = ZlpDirectoryInfo.GetTemp().CombineDirectory(Guid.NewGuid().ToString()).CheckCreate();

            try
            {
                var p1 = path.CombineDirectory(@"a").CheckCreate();
                var p2 = path.CombineDirectory(@"b");

                var f1 = p1.CombineFile("1.txt");
                f1.WriteAllText("1");

                Assert.DoesNotThrow(() => p1.MoveTo(p2));
            }
            finally
            {
                path.SafeDelete();
            }
        }
Example #25
0
        public void TestFolders()
        {
            var dirInfo1 = new ZlpDirectoryInfo(@"C:\Foo\Bar");

            Console.WriteLine(dirInfo1.Name); //"Bar"
            var dirInfo2 = new ZlpDirectoryInfo(@"C:\Foo\Bar\");

            Console.WriteLine(dirInfo2.Name); //"", an empty string

            var dirInfo3 = new DirectoryInfo(@"C:\Foo\Bar");

            Console.WriteLine(dirInfo1.Name);
            var dirInfo4 = new DirectoryInfo(@"C:\Foo\Bar\");

            Console.WriteLine(dirInfo2.Name);

            Assert.AreEqual(dirInfo1.Name, dirInfo3.Name);
            Assert.AreEqual(dirInfo2.Name, dirInfo4.Name);
        }
Example #26
0
        private void PopulateRequestWorkingDirectory()
        {
            Assert.DirectoryExists(this.Request.SourcePath, "Unable to find request source directory path.");

            string tempPath = Path.Combine(Program.TempFolderPath, this.Request.RequestId.ToString("N").Substring(0, 10));

            this.TempDirectory = new DirectoryInfo(tempPath);

            Assert.DirectoryDoesNotExist(this.TempDirectory, "The request working directory already exists.");

            this.TempDirectory.Create();

            Assert.DirectoryExists(this.TempDirectory, "Failed to create request working directory.");

            this.TempContentDirectory.Create();

            ZlpDirectoryInfo sourceDirectory = new ZlpDirectoryInfo(this.Request.SourcePath);

            FileSystemUtil.CopyDirectory(sourceDirectory, this.TempContentDirectory, true);
        }
Example #27
0
        public void PhanLoaiBa()
        {
            string           input  = File.ReadAllText(Environment.CurrentDirectory + "\\input.txt");
            ZlpDirectoryInfo folder = new ZlpDirectoryInfo(input);

            foreach (ZlpDirectoryInfo itemFolder in folder.GetDirectories())
            {
                foreach (ZlpDirectoryInfo item in itemFolder.GetDirectories())
                {
                    foreach (ZlpDirectoryInfo itemProduct in itemFolder.GetDirectories())
                    {
                        foreach (ZlpDirectoryInfo file in itemProduct.GetDirectories())
                        {
                            foreach (ZlpFileInfo itemFile in file.GetFiles())
                            {
                                try
                                {
                                    string name = itemFile
                                                  .Name.Replace(" ", "-").Replace(" ", "-")
                                                  .Replace(" ", "-").Replace(" ", "-")
                                                  .Replace("--", "-").Replace("--", "-")
                                                  .Replace("--", "-").Replace("--", "-").Replace("--", "-");
                                    itemFile.CopyTo(file.GetFullPath() + "\\" + Regex.Replace(name, "[^a-zA-Z0-9._-]", string.Empty), true);
                                    itemFile.Delete();
                                    Console.ForegroundColor = (System.ConsoleColor) new Random().Next(0, 14);
                                    Console.WriteLine(file.FullName);
                                }
                                catch
                                {
                                }
                                finally
                                {
                                    GC.Collect();
                                }
                            }
                        }
                    }
                }
            }
        }
Example #28
0
        /// <summary>
        /// Gets list of strings where each is full path to file including filename (for example: <example>c:\dir\filename.ext</example>.
        /// </summary>
        /// <param name="folderPath">Full path of folder that should be searched. For example: <example>c:\dir</example>.</param>
        /// <returns></returns>
        private static List <string> GetFilePathsUsingZetaForLongPaths(string folderPath, bool recursively = false, string searchPattern = null)
        {
            if (String.IsNullOrEmpty(folderPath))
            {
                throw new ArgumentException("Value must be non-empty string.", "folderPath");
            }

            List <string> r = new List <string>();

            ZetaLongPaths.ZlpDirectoryInfo zdi = new ZlpDirectoryInfo(folderPath);
            if (zdi.Exists)
            {
                ZlpFileInfo[] files = null;
                if (searchPattern == null)
                {
                    files = zdi.GetFiles(SearchOption.AllDirectories);
                }
                else
                {
                    files = zdi.GetFiles(searchPattern, SearchOption.AllDirectories);
                }
                foreach (ZlpFileInfo zlpFileInfo in files)
                {
                    r.Add(zlpFileInfo.FullName);
                }

                if (recursively)
                {
                    ZlpDirectoryInfo[] subfolders     = zdi.GetDirectories(folderPath);
                    List <string>      subfolderFiles = null;
                    foreach (ZlpDirectoryInfo subfolder in subfolders)
                    {
                        subfolderFiles = GetFilePathsUsingZetaForLongPaths(subfolder.FullName, recursively, searchPattern);
                        r.AddRange(subfolderFiles);
                    }
                }
            }

            return(r);
        }
Example #29
0
        private static void Main(string[] args)
        {
            var f1 = new ZlpFileInfo(@"C:\Ablage\test-only\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Lalala.txt");

            f1.Directory.Create();
            f1.WriteAllText("lalala.");
            Console.WriteLine(f1.Length);

            new ZlpDirectoryInfo(@"C:\Ablage\test-only\").Delete(true);
            //f1.MoveToRecycleBin();


            var f = new ZlpFileInfo(@"C:\Ablage\Lalala.txt");

            f.WriteAllText("lalala.");
            f.MoveToRecycleBin();

            var d = new ZlpDirectoryInfo(@"C:\Ablage\LalalaOrdner");

            d.Create();
            d.MoveToRecycleBin();
        }
Example #30
0
        public void TestMD5()
        {
            var tempRootFolder = ZlpDirectoryInfo.GetTemp();

            Assert.True(tempRootFolder.Exists);

            var tempFolderPath = tempRootFolder.CombineDirectory(Guid.NewGuid().ToString(@"N"));

            tempFolderPath.CheckCreate();

            try
            {
                var file = tempFolderPath.CombineFile(@"one.txt");
                file.WriteAllText(@"Franz jagt im komplett verwahrlosten Taxi quer durch Bayern.");

                var hash = file.MD5Hash;
                Assert.AreEqual(hash, @"ba4b9da310763a91f8edc7c185a1e4bf");
            }
            finally
            {
                tempFolderPath.Delete(true);
            }
        }
		public void TestToString()
		{
			var a = new ZlpDirectoryInfo(@"C:\ablage\test.txt");
			var b = new DirectoryInfo(@"C:\ablage\test.txt");

			var x = a.ToString();
			var y = b.ToString();

			Assert.AreEqual(x, y);

			// --

			a = new ZlpDirectoryInfo(@"C:\ablage\");
			b = new DirectoryInfo(@"C:\ablage\");

			x = a.ToString();
			y = b.ToString();

			Assert.AreEqual(x, y);

			// --

			a = new ZlpDirectoryInfo(@"test.txt");
			b = new DirectoryInfo(@"test.txt");

			x = a.ToString();
			y = b.ToString();

			Assert.AreEqual(x, y);

			// --

			a = new ZlpDirectoryInfo(@"c:\ablage\..\ablage\test.txt");
			b = new DirectoryInfo(@"c:\ablage\..\ablage\test.txt");

			x = a.ToString();
			y = b.ToString();

			Assert.AreEqual(x, y);

			// --

			a = new ZlpDirectoryInfo(@"\ablage\test.txt");
			b = new DirectoryInfo(@"\ablage\test.txt");

			x = a.ToString();
			y = b.ToString();

			Assert.AreEqual(x, y);

			// --

			a = new ZlpDirectoryInfo(@"ablage\test.txt");
			b = new DirectoryInfo(@"ablage\test.txt");

			x = a.ToString();
			y = b.ToString();

			Assert.AreEqual(x, y);
		}
		public void TestGeneral()
		{
            // Ordner mit Punkt am Ende.
            string dir = $@"C:\Ablage\{Guid.NewGuid():N}.";
            Assert.IsFalse(new ZlpDirectoryInfo(dir).Exists);
            new ZlpDirectoryInfo(dir).CheckCreate();
            Assert.IsTrue(new ZlpDirectoryInfo(dir).Exists);
            new ZlpDirectoryInfo(dir).Delete(true);
            Assert.IsFalse(new ZlpDirectoryInfo(dir).Exists);


			//Assert.IsTrue(new ZlpDirectoryInfo(Path.GetTempPath()).CreationTime>DateTime.MinValue);
			//Assert.IsTrue(new ZlpDirectoryInfo(Path.GetTempPath()).Exists);
			//Assert.IsFalse(new ZlpDirectoryInfo(@"C:\Ablage\doesnotexistjdlkfjsdlkfj").Exists);
			//Assert.IsTrue(new ZlpDirectoryInfo(Path.GetTempPath()).Exists);
			//Assert.IsFalse(new ZlpDirectoryInfo(@"C:\Ablage\doesnotexistjdlkfjsdlkfj2").Exists);
			//Assert.IsFalse(new ZlpDirectoryInfo(@"\\zetac11\C$\Ablage").Exists);
			//Assert.IsFalse(new ZlpDirectoryInfo(@"\\zetac11\C$\Ablage\doesnotexistjdlkfjsdlkfj2").Exists);

			const string s1 = @"C:\Users\Chris\Documents\Development\ADC\InterStore.NET\Visual Studio 2008\6.4.2\Zeta Resource Editor";
			const string s2 = @"C:\Users\Chris\Documents\Development\ADC\InterStore.NET\Visual Studio 2008\6.4.2\Web\central\Controls\App_LocalResources\ItemSearch";

			var s3 = ZlpPathHelper.GetRelativePath(s1, s2);
			Assert.AreEqual(s3, @"..\Web\central\Controls\App_LocalResources\ItemSearch");

			var ext = ZlpPathHelper.GetExtension(s3);
			Assert.IsNullOrEmpty(ext);

			ext = ZlpPathHelper.GetExtension(@"C:\Ablage\Uwe.txt");
			Assert.AreEqual(ext, @".txt");

			const string path = @"C:\Ablage\Test";
			Assert.AreEqual(
				new DirectoryInfo(path).Name,
				new ZlpDirectoryInfo(path).Name);

			Assert.AreEqual(
				new DirectoryInfo(path).FullName,
				new ZlpDirectoryInfo(path).FullName);

			const string filePath = @"C:\Ablage\Test\file.txt";
			var fn1 = new FileInfo(filePath).Directory?.FullName;
			var fn2 = new ZlpFileInfo(filePath).Directory.FullName;

			var fn1A = new FileInfo(filePath).DirectoryName;
			var fn2A = new ZlpFileInfo(filePath).DirectoryName;

			Assert.AreEqual(fn1,fn2);
			Assert.AreEqual(fn1A,fn2A);

			var fn = new ZlpDirectoryInfo(@"\\zetac11\C$\Ablage\doesnotexistjdlkfjsdlkfj2").Parent.FullName;

			Assert.AreEqual(fn, @"\\zetac11\C$\Ablage");

			fn = new ZlpDirectoryInfo(@"\\zetac11\C$\Ablage\doesnotexistjdlkfjsdlkfj2\").Parent.FullName;

			Assert.AreEqual(fn, @"\\zetac11\C$\Ablage");
		}