文件名复制算法

Avi*_*ash 3 algorithm

当我在Windows中复制以下文件在同一目录中时.

"Log.txt"将其复制为"Log.txt的副本"如果现在再次复制"Copy of Log.txt",它将被复制为"Log.txt的副本副本"如果现在再次复制"Log of Log" .txt"它被复制为"Copy of Log.txt的Copy(2)"

任何人都知道这里使用了什么算法.

jas*_*son 9

这很简单:

// 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);
Run Code Online (Sandbox Code Playgroud)