Beispiel #1
0
 private void StartRename()
 {
     try
     {
         string path = WildcardCharacterHelper.TranslateWildcardDirectoryPath(options.InputDirectory);
         SearchDirectory(path);
     }
     catch (CommandLineException ex)
     {
         RaiseCommandLineException(this, ex);
     }
 }
Beispiel #2
0
 private void StartSyncCopy()
 {
     try
     {
         string fromDirectory = WildcardCharacterHelper.TranslateWildcardDirectoryPath(options.FromDirectory);
         string toDirectory   = WildcardCharacterHelper.TranslateWildcardDirectoryPath(options.ToDirectory);
         SyncCopy(fromDirectory, toDirectory);
     }
     catch (CommandLineException ex)
     {
         RaiseCommandLineException(this, ex);
     }
 }
Beispiel #3
0
 private void StartSelect()
 {
     try
     {
         if (options.IsSetDirectory)
         {
             string path = WildcardCharacterHelper.TranslateWildcardDirectoryPath(options.Directory);
             SelectDirectory(path);
         }
     }
     catch (CommandLineException ex)
     {
         RaiseCommandLineException(this, ex);
     }
 }
Beispiel #4
0
 private void StartSplit()
 {
     try
     {
         if (options.IsSetFile)
         {
             string file   = WildcardCharacterHelper.TranslateWildcardFilePath(options.File);
             string folder = WildcardCharacterHelper.TranslateWildcardDirectoryPath(options.Directory);
             SplitFile(file, folder);
         }
     }
     catch (CommandLineException ex)
     {
         RaiseCommandLineException(this, ex);
     }
 }
Beispiel #5
0
 private void StartGrep()
 {
     try
     {
         foreach (var item in options.FilePaths)
         {
             string path = WildcardCharacterHelper.TranslateWildcardDirectoryPath(item);
             if (options.IsSetDirectory)
             {
                 GrepDirectory(path);
             }
             else
             {
                 if (WildcardCharacterHelper.IsContainsWildcard(path))
                 {
                     string dir = path;
                     if (!path.Contains("\\") && !path.Contains("/"))
                     {
                         dir = Environment.CurrentDirectory + Path.DirectorySeparatorChar + path;
                     }
                     FileInfo[] files = new DirectoryInfo(Path.GetDirectoryName(dir)).GetFiles();
                     foreach (var file in files.OrderBy(f => f.LastWriteTime).ThenBy(f => f.Name))
                     {
                         Regex r = new Regex(WildcardCharacterHelper.TranslateWildcardToRegex(path));
                         if (r.IsMatch(file.FullName) || r.IsMatch(file.Name))
                         {
                             GrepFile(file.FullName);
                         }
                     }
                 }
                 else
                 {
                     GrepFile(path);
                 }
             }
         }
     }
     catch (ArgumentException ex)
     {
         RaiseCommandLineException(this, new CommandLineException("Path is invalid.", ex));
     }
     catch (CommandLineException ex)
     {
         RaiseCommandLineException(this, ex);
     }
 }
Beispiel #6
0
        private void StartCopyFiles()
        {
            try
            {
                if (options.IsSetSourceFolder && options.IsSetDestinationFolder)
                {
                    string sourceFolder      = WildcardCharacterHelper.TranslateWildcardDirectoryPath(options.SourceFolder);
                    string destinationFolder = WildcardCharacterHelper.TranslateWildcardDirectoryPath(options.DestinationFolder);

                    CopySameFiles(sourceFolder, destinationFolder);
                }
            }
            catch (CommandLineException ex)
            {
                RaiseCommandLineException(this, ex);
            }
        }
Beispiel #7
0
        private void StartCount()
        {
            try
            {
                if (options.IsSetDirectory)
                {
                    string path = WildcardCharacterHelper.TranslateWildcardDirectoryPath(options.Directory);
                    CountDirectory(path);
                }

                foreach (var item in countSummary.OrderByDescending(t => t.Value).ThenBy(w => w.Key))
                {
                    OutputText(string.Format(CultureInfo.CurrentCulture, "FileType: {0,-30}Count: {1}", item.Key.ToLowerInvariant(), item.Value));
                }
            }
            catch (CommandLineException ex)
            {
                RaiseCommandLineException(this, ex);
            }
        }
        private void StartExtract()
        {
            try
            {
                DateTime executeBeginTime = DateTime.Now;

                string path = WildcardCharacterHelper.TranslateWildcardDirectoryPath(options.InputDirectory);
                ExtractDirectory(path);

                DateTime executeEndTime = DateTime.Now;
                TimeSpan duration       = executeEndTime - executeBeginTime;
                OutputText(Environment.NewLine);
                OutputText(string.Format(CultureInfo.CurrentCulture, "Extract Begin Time : {0}", executeBeginTime.ToString(@"yyyy-MM-dd HH:mm:ss")));
                OutputText(string.Format(CultureInfo.CurrentCulture, "Extract End   Time : {0}", executeEndTime.ToString(@"yyyy-MM-dd HH:mm:ss")));
                OutputText(string.Format(CultureInfo.CurrentCulture, "Extract Total Time : {0}",
                                         string.Format("{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms",
                                                       duration.Hours, duration.Minutes, duration.Seconds, duration.Milliseconds)));
            }
            catch (CommandLineException ex)
            {
                RaiseCommandLineException(this, ex);
            }
        }
Beispiel #9
0
        private string GetDepthOutputDirectory(string outputDirectory, string fileDirectoryName)
        {
            string outputPath = outputDirectory;

            if (options.IsSetKeepDepth)
            {
                string selectPath = WildcardCharacterHelper.TranslateWildcardDirectoryPath(options.Directory);
                string partDir    = fileDirectoryName.Replace(selectPath, "")
                                    .TrimStart(new char[] { '/', '\\' })
                                    .TrimEnd(new char[] { '/', '\\' })
                                    .Replace('/', '|')
                                    .Replace('\\', '|');
                if (!string.IsNullOrEmpty(partDir))
                {
                    string[] depthDirList = partDir.Split('|').Take(options.KeepDepth).ToArray();
                    foreach (var item in depthDirList)
                    {
                        outputPath = Path.Combine(outputPath, item);
                    }
                }
            }

            return(outputPath);
        }
Beispiel #10
0
        private void StartEncode()
        {
            try
            {
                if (options.IsSetInputFile)
                {
                    string path = WildcardCharacterHelper.TranslateWildcardFilePath(options.InputFile);
                    if (WildcardCharacterHelper.IsContainsWildcard(path))
                    {
                        FileInfo[] files = new DirectoryInfo(Path.GetDirectoryName(path)).GetFiles();
                        foreach (var file in files)
                        {
                            Regex r = new Regex(WildcardCharacterHelper.TranslateWildcardToRegex(path));
                            if (r.IsMatch(file.FullName) || r.IsMatch(file.Name))
                            {
                                EncodeFile(file.FullName);
                            }
                        }
                    }
                    else
                    {
                        EncodeFile(path);
                    }
                }

                if (options.IsSetDirectory)
                {
                    string path = WildcardCharacterHelper.TranslateWildcardDirectoryPath(options.Directory);
                    EncodeDirectory(path);
                }
            }
            catch (CommandLineException ex)
            {
                RaiseCommandLineException(this, ex);
            }
        }
Beispiel #11
0
        private void SelectFile(string directoryName, string fileName)
        {
            try
            {
                string[] extensions = options.Extension.Split(new char[] { ',', ';' });
                foreach (var extension in extensions)
                {
                    if (fileName.EndsWith(extension))
                    {
                        if (options.IsSetOutput)
                        {
                            string        outputBase    = WildcardCharacterHelper.TranslateWildcardDirectoryPath(options.Output);
                            DirectoryInfo outputBaseDir = new DirectoryInfo(outputBase);
                            if (!outputBaseDir.Exists)
                            {
                                throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                                             "No such directory -- {0}", outputBaseDir.FullName));
                            }

                            string        outputPath    = GetDepthOutputDirectory(outputBase, directoryName);
                            DirectoryInfo outputPathDir = new DirectoryInfo(outputPath);
                            if (!outputPathDir.Exists)
                            {
                                outputPathDir.Create();
                            }

                            if (options.IsSetMove)
                            {
                                File.Move(Path.Combine(directoryName, fileName), Path.Combine(outputPath, fileName));
                                OutputText(string.Format(CultureInfo.CurrentCulture, "Move file from -> {0}", Path.Combine(directoryName, fileName)));
                                OutputText(string.Format(CultureInfo.CurrentCulture, "            to -> {0}", Path.Combine(outputPath, fileName)));
                            }
                            else if (options.IsSetCopy)
                            {
                                File.Copy(Path.Combine(directoryName, fileName), Path.Combine(outputPath, fileName), true);
                                OutputText(string.Format(CultureInfo.CurrentCulture, "Copy file from -> {0}", Path.Combine(directoryName, fileName)));
                                OutputText(string.Format(CultureInfo.CurrentCulture, "            to -> {0}", Path.Combine(outputPath, fileName)));
                            }
                        }
                    }
                }
            }
            catch (NotSupportedException ex)
            {
                throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                             "Operation exception -- {0}, {1}", Path.Combine(directoryName, fileName), ex.Message));
            }
            catch (PathTooLongException ex)
            {
                throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                             "Operation exception -- {0}, {1}", Path.Combine(directoryName, fileName), ex.Message));
            }
            catch (FileNotFoundException ex)
            {
                throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                             "Operation exception -- {0}, {1}", Path.Combine(directoryName, fileName), ex.Message));
            }
            catch (UnauthorizedAccessException ex)
            {
                throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                             "Operation exception -- {0}, {1}", Path.Combine(directoryName, fileName), ex.Message));
            }
            catch (DirectoryNotFoundException ex)
            {
                throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                             "Operation exception -- {0}, {1}", Path.Combine(directoryName, fileName), ex.Message));
            }
            catch (SecurityException ex)
            {
                throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                             "Operation exception -- {0}, {1}", Path.Combine(directoryName, fileName), ex.Message));
            }
            catch (IOException ex)
            {
                throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                             "Operation exception -- {0}, {1}", Path.Combine(directoryName, fileName), ex.Message));
            }
        }