Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

Bugfix/manga reader pad zeros (#288)

Robbie Davis4f29cf7cc7fa
diff --git a/API/Extensions/DirectoryInfoExtensions.cs b/API/Extensions/DirectoryInfoExtensions.cs
index c41ca9f8b..0eaf6c00a 100644
--- a/API/Extensions/DirectoryInfoExtensions.cs
+++ b/API/Extensions/DirectoryInfoExtensions.cs
@@ -1,12 +1,12 @@
-using System;
-using System.IO;
+using System.IO;
using System.Linq;
-using API.Services;
+using API.Comparators;
namespace API.Extensions
{
public static class DirectoryInfoExtensions
{
+ private static readonly NaturalSortComparer Comparer = new NaturalSortComparer();
public static void Empty(this DirectoryInfo directory)
{
foreach(FileInfo file in directory.EnumerateFiles()) file.Delete();
@@ -49,12 +49,13 @@ namespace API.Extensions
if (!root.FullName.Equals(directory.FullName))
{
var fileIndex = 1;
- foreach (var file in directory.EnumerateFiles())
+
+ foreach (var file in directory.EnumerateFiles().OrderBy(file => file.FullName, Comparer))
{
if (file.Directory == null) continue;
var paddedIndex = Parser.Parser.PadZeros(directoryIndex + "");
// We need to rename the files so that after flattening, they are in the order we found them
- var newName = $"{paddedIndex}_{fileIndex}.{file.Extension}";
+ var newName = $"{paddedIndex}_{Parser.Parser.PadZeros(fileIndex + "")}{file.Extension}";
var newPath = Path.Join(root.FullName, newName);
if (!File.Exists(newPath)) file.MoveTo(newPath);
fileIndex++;