コード例 #1
0
        public void RenameFiles()
        {
            List <EpisodeForComparingDto> sourceEps = _localservice.GetFilesAsDtosToCompare();

            foreach (EpisodeForComparingDto epDto in sourceEps)
            {
                try {
                    Episode epEntity = _episodeService.FindByEpisodeForComparingDto(epDto);
                    if (epEntity != null)
                    {
                        EpisodeForComparingDto targetDto = CreateEpisodeForComparingDtoFromEntity(epEntity);
                        string localFile    = Path.GetFileName(epDto.FilePath);
                        string targetName   = targetDto.GetFormattedFilename();
                        bool   shouldRename = _prompter.PromptForRename(localFile, targetName);
                        if (shouldRename)
                        {
                            _localservice.RenameFile(epDto.FilePath, targetDto);
                        }
                    }
                    else
                    {
                        Log.Information("Could not find a matching database entry for {epFileName}. Make sure the series name matches.", epDto.FilePath);
                    }
                }
                catch (Exception e) {
                    Log.Warning(e, "Could not rename file {a}", epDto.FilePath);
                }
            }
        }
コード例 #2
0
 public void RenameFile(string filePath, EpisodeForComparingDto ep)
 {
     try {
         string extension       = Path.GetExtension(filePath);
         string sourceDirectory = Path.GetDirectoryName(filePath);
         string newFilename     = ep.GetFormattedFilename();
         string newPath         = Path.Combine(sourceDirectory, $"{newFilename}{extension}");
         File.Move(filePath, newPath);
         Log.Information("Renamed {a} to {b}", Path.GetFileName(filePath), Path.GetFileName(newPath));
     }
     catch (Exception e) {
         Log.Error(e.Message);
     }
 }