mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
New: Remove empty subfolders after renaming FileSetLastWriteTime
Closes #490
This commit is contained in:
parent
1603b06431
commit
1a5eafd2b1
@ -418,5 +418,19 @@ public List<FileInfo> GetFileInfos(string path)
|
||||
|
||||
return di.GetFiles().ToList();
|
||||
}
|
||||
|
||||
public void RemoveEmptySubfolders(string path)
|
||||
{
|
||||
var subfolders = GetDirectories(path);
|
||||
var files = GetFiles(path, SearchOption.AllDirectories);
|
||||
|
||||
foreach (var subfolder in subfolders)
|
||||
{
|
||||
if (files.None(f => subfolder.IsParentPath(f)))
|
||||
{
|
||||
DeleteFolder(path, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,5 +47,6 @@ public interface IDiskProvider
|
||||
IMount GetMount(string path);
|
||||
List<DirectoryInfo> GetDirectoryInfos(string path);
|
||||
List<FileInfo> GetFileInfos(string path);
|
||||
void RemoveEmptySubfolders(string path);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Instrumentation.Extensions;
|
||||
using NzbDrone.Core.MediaFiles.Commands;
|
||||
@ -30,6 +31,7 @@ public class RenameEpisodeFileService : IRenameEpisodeFileService,
|
||||
private readonly IEventAggregator _eventAggregator;
|
||||
private readonly IEpisodeService _episodeService;
|
||||
private readonly IBuildFileNames _filenameBuilder;
|
||||
private readonly IDiskProvider _diskProvider;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public RenameEpisodeFileService(ISeriesService seriesService,
|
||||
@ -38,6 +40,7 @@ public RenameEpisodeFileService(ISeriesService seriesService,
|
||||
IEventAggregator eventAggregator,
|
||||
IEpisodeService episodeService,
|
||||
IBuildFileNames filenameBuilder,
|
||||
IDiskProvider diskProvider,
|
||||
Logger logger)
|
||||
{
|
||||
_seriesService = seriesService;
|
||||
@ -46,6 +49,7 @@ public RenameEpisodeFileService(ISeriesService seriesService,
|
||||
_eventAggregator = eventAggregator;
|
||||
_episodeService = episodeService;
|
||||
_filenameBuilder = filenameBuilder;
|
||||
_diskProvider = diskProvider;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@ -134,6 +138,8 @@ private void RenameFiles(List<EpisodeFile> episodeFiles, Series series)
|
||||
|
||||
if (renamed.Any())
|
||||
{
|
||||
_diskProvider.RemoveEmptySubfolders(series.Path);
|
||||
|
||||
_eventAggregator.PublishEvent(new SeriesRenamedEvent(series));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user