Browse Source

+FileUtils Extension : Basename to retrieve the name of the file, without extension.
+FileUtils.ChangeExtension : change the extension of a file

Aryx 2 months ago
parent
commit
7c4cb54516

+ 1 - 0
AryxDevLibrary.csproj

@@ -73,6 +73,7 @@
     <Compile Include="constants\EnumOtherEncoding.cs" />
     <Compile Include="EnumUtils.cs" />
     <Compile Include="extensions\DateUtilsExt.cs" />
+    <Compile Include="extensions\FileUtils.cs" />
     <Compile Include="extensions\StringUtilsExt.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="utils\BooleansContainers.cs" />

File diff suppressed because it is too large
+ 0 - 1
AryxDevLibrary.sln.DotSettings.user


BIN
AryxDevLibrary.v12.suo


+ 2 - 2
AssemblyTTempl.cs

@@ -6,6 +6,6 @@
 using System.Reflection;
 
 
-[assembly: AssemblyVersion("1.0.4.331")]
-[assembly: AssemblyFileVersion("1.0.4.331")]
+[assembly: AssemblyVersion("1.0.5.17")]
+[assembly: AssemblyFileVersion("1.0.5.17")]
 

+ 18 - 0
extensions/FileUtils.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace AryxDevLibrary.extensions
+{
+    public static class FileUtils
+    {
+
+        public static String Basename(this FileInfo file)
+        {
+            return file.Name.Replace(file.Extension, "");
+        }
+
+    }
+}

+ 31 - 6
utils/FileUtils.cs

@@ -13,21 +13,36 @@ using AryxDevLibrary.extensions;
 
 namespace AryxDevLibrary.utils
 {
+    /// <summary>
+    /// Static methods for file manipulation.
+    /// </summary>
     public static class FileUtils
     {
         private static readonly string[] Sizes = { "o", "ko", "Mo", "Go", "To" };
 
+        /// <summary>
+        /// Retrieve the path of the desktop (current user).
+        /// </summary>
+        /// <returns>the path of the desktop (current user)</returns>
         public static string GetDesktopPath()
         {
             return Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
         }
 
+        /// <summary>
+        /// Displays the file in Windows Explorer. If the file does not exist, Windows Explorer will still be open.
+        /// </summary>
+        /// <param name="stringPath">The path of the file to show</param>
         public static void ShowFileInWindowsExplorer(String stringPath)
         {
             FileInfo fi = new FileInfo(stringPath);
             ShowFileInWindowsExplorer(fi);
         }
 
+        /// <summary>
+        /// Displays the file in Windows Explorer. If the file does not exist, Windows Explorer will still be open.
+        /// </summary>
+        /// <param name="stringPath">The file to show</param>
         public static void ShowFileInWindowsExplorer(FileSystemInfo file)
         {
             Process.Start("explorer.exe", "/select, \"" + file.FullName + "\"");
@@ -84,17 +99,17 @@ namespace AryxDevLibrary.utils
                 {
                     retDouble = dblSize * Math.Pow(2, 10 * i);
                 }
-
-
-
-
-
             }
 
             return retDouble;
 
         }
 
+        /// <summary>
+        /// Returns the files list of the active directory, as well as all accessible subdirectories.
+        /// </summary>
+        /// <param name="path">The files list of the active directory, as well as all accessible subdirectories</param>
+        /// <returns></returns>
         public static List<FileInfo> GetFilesRecursively(DirectoryInfo path)
         {
             if (path == null)
@@ -312,6 +327,16 @@ namespace AryxDevLibrary.utils
             return new StreamWriter(File.Open(filename, filemode), Encoding.GetEncoding(encodingName));
         }
 
-
+        /// <summary>
+        /// Change the file extension.
+        /// </summary>
+        /// <param name="file"></param>
+        /// <param name="newExtension">the new extension, need to start with a dot.</param>
+        /// <returns></returns>
+        public static FileInfo ChangeExtension(FileInfo file, String newExtension)
+        {
+            string newFileN = file.FullName.Replace(file.Extension, newExtension);
+            return new FileInfo(newFileN);
+        }
     }
 }

Some files were not shown because too many files changed in this diff