@@ -580,9 +580,10 @@ public static Task SetClipboard(string[] filesToCopy, DataPackageOperation opera
580
580
{
581
581
using ShellItem shi = new ( fileToCopyPath [ i ] ) ;
582
582
using ShellFolder shd = new ( Path . GetDirectoryName ( copyDestination [ i ] ) ) ;
583
-
584
- // Performa copy operation
585
- op . QueueCopyOperation ( shi , shd , Path . GetFileName ( copyDestination [ i ] ) ) ;
583
+
584
+ var fileName = GetIncrementalName ( overwriteOnCopy , copyDestination [ i ] , fileToCopyPath [ i ] ) ;
585
+ // Perform a copy operation
586
+ op . QueueCopyOperation ( shi , shd , fileName ) ;
586
587
} ) )
587
588
{
588
589
shellOperationResult . Items . Add ( new ShellOperationItemResult ( )
@@ -1018,5 +1019,26 @@ protected override void Dispose(bool disposing)
1018
1019
}
1019
1020
}
1020
1021
}
1022
+
1023
+ private static string GetIncrementalName ( bool overWriteOnCopy , string ? filePathToCheck , string ? filePathToCopy )
1024
+ {
1025
+ if ( filePathToCheck == null )
1026
+ return null ;
1027
+
1028
+ if ( ( ! Path . Exists ( filePathToCheck ) ) || overWriteOnCopy || filePathToCheck == filePathToCopy )
1029
+ return Path . GetFileName ( filePathToCheck ) ;
1030
+
1031
+ var index = 2 ;
1032
+ var filePath = filePathToCheck ;
1033
+ if ( Path . HasExtension ( filePathToCheck ) )
1034
+ filePath = filePathToCheck . Substring ( 0 , filePathToCheck . LastIndexOf ( "." ) ) ;
1035
+
1036
+ Func < int , string > genFilePath = x => string . Concat ( [ filePath , " (" , x . ToString ( ) , ")" , Path . GetExtension ( filePathToCheck ) ] ) ;
1037
+
1038
+ while ( Path . Exists ( genFilePath ( index ) ) )
1039
+ index ++ ;
1040
+
1041
+ return Path . GetFileName ( genFilePath ( index ) ) ;
1042
+ }
1021
1043
}
1022
1044
}
0 commit comments