rawfilewizard

git clone https://git.clttr.info/rawfilewizard.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

FileHelpers.cs (2564B)


      1 using SilkypixFileMover.Properties;
      2 using System.Collections.Generic;
      3 using System.IO;
      4 
      5 namespace SilkypixFileMover.Helpers
      6 {
      7     internal static class FileHelpers
      8     {
      9         internal static void SaveMove( string sourceFileName, string destinationFileName)
     10         {
     11             if ( Directory.Exists( Path.GetDirectoryName( sourceFileName ) ) )
     12             {
     13                 if ( File.Exists( sourceFileName ) )
     14                 {
     15                     File.Move( sourceFileName, destinationFileName );
     16                 }
     17             }
     18         }
     19 
     20         internal static void SaveDelete( string fileName )
     21         {
     22             if ( Directory.Exists( Path.GetDirectoryName( fileName ) ) )
     23             {
     24                 if ( File.Exists( fileName ) )
     25                 {
     26                     if (Settings.Default.MoveToRecycleBin)
     27                     {
     28                         if ( !FileOperationAPIWrapper.MoveToRecycleBin(fileName))
     29                         {
     30                             throw new IOException("File could not be deleted.");
     31                         }
     32                     }
     33                     else
     34                     {
     35                         File.Delete(fileName);
     36                     }
     37                 }
     38             }
     39         }
     40 
     41         internal static void MoveAllFilesInList( IEnumerable<string> fileList, string sourceFolder, string destinationFolder, bool save )
     42         {
     43             foreach ( string file in fileList )
     44             {
     45                 string sourceFullPath = Path.Combine( sourceFolder, file );
     46                 if ( !Directory.Exists(Path.GetDirectoryName(sourceFullPath)))
     47                 {
     48                     continue;
     49                 }
     50                 if ( !File.Exists(sourceFullPath))
     51                 {
     52                     continue;
     53                 }
     54                 string destFullPath = Path.Combine( destinationFolder, Path.GetFileName( file ) );
     55 
     56                 if (save)
     57                 {
     58                     SaveMove(sourceFullPath, destFullPath);
     59                 }
     60                 else
     61                 {
     62                     File.Move(sourceFullPath, destFullPath);
     63                 }
     64             }
     65         }
     66 
     67         internal static void DeleteAllFilesInList( IEnumerable<string> fileList, string folder )
     68         {
     69             foreach ( string file in fileList )
     70             {
     71                 string fileFullSourcePath = Path.Combine( folder, file );
     72 
     73                 SaveDelete( fileFullSourcePath );
     74             }
     75         }
     76     }
     77 }