Skip to content

Commit 4f94d4e

Browse files
author
LoneWandererProductions
committed
fix another small subtile bug.
1 parent eaf35be commit 4f94d4e

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

CommonLibraryGuiTests/Plugins.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public sealed class Plugins
2525
[Apartment(ApartmentState.STA)]
2626
public void LoadPluginSqliIte()
2727
{
28-
var root = DirectoryInformation.GetParentDirectory(3);
28+
var root = DirectoryInformation.GetParentDirectory(4);
2929
var target = Path.Combine(root, @"SqlLiteGui\bin\Debug\net9.0-windows");
3030
var check = PluginLoad.LoadAll(target);
3131

FileHandler/FileUtility.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,30 @@ namespace FileHandler;
1515
public static class FileUtility
1616
{
1717
/// <summary>
18-
/// Gets the new name of the file, if it already exists
18+
/// Returns a new file path if the given file already exists by appending a numeric suffix.
19+
/// Example: file.txt → file(0).txt, file(1).txt, etc.
1920
/// </summary>
20-
/// <param name="path">The path.</param>
21-
/// <returns>new Path with new FileName</returns>
21+
/// <param name="path">The full file path.</param>
22+
/// <returns>New unique file path, or null if path is invalid.</returns>
2223
public static string? GetNewFileName(string path)
2324
{
2425
if (!File.Exists(path))
25-
{
2626
return null;
27-
}
2827

28+
var directory = Path.GetDirectoryName(path);
2929
var fileNameOnly = Path.GetFileNameWithoutExtension(path);
3030
var extension = Path.GetExtension(path);
31-
var directory = Path.GetDirectoryName(path);
31+
3232
if (string.IsNullOrEmpty(directory) || !Directory.Exists(directory))
33-
{
3433
return null;
35-
}
3634

3735
var newPath = path;
3836
var count = 0;
3937

4038
while (File.Exists(newPath))
4139
{
42-
var cache = $"{fileNameOnly}({count++}){extension}";
43-
newPath = Path.Combine(directory, cache);
40+
newPath = Path.Combine(directory, fileNameOnly + "(" + count + ")" + extension);
41+
count++;
4442
}
4543

4644
return newPath;

0 commit comments

Comments
 (0)