File Name Copy Algorithms

When I copy the following file to Windows in the same directory.

“Log.txt” it will be copied as “Copy of log .txt” If now copy “Copy Log.txt” again, it will be copied as “Copy of log .txt”, If now again I will copy “Copy of log .txt”, it copied as "Copy (2) copies of the .txt journal"

Does anyone know which algorithm is used here.

+3
source share
1 answer

It's simple:

// source is string representing path of source file to copy
string dest = "Copy of " + source;
int count = 2;
while(File.Exists(dest)) {
    dest = "Copy (" + count.ToString() + ") of " + source;
    count++;
}
File.Copy(source, dest);
+9
source

Source: https://habr.com/ru/post/1731025/


All Articles