tags:

views:

67

answers:

1

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

"Log.txt" it get copied as "Copy of Log.txt" If now copy "Copy of Log.txt" again , it gets copied as "Copy of Copy of Log.txt" If now again I copy "Copy of Log.txt" it gets copied as "Copy (2) of Copy of Log.txt"

Anybody aware of what algorithm is used here.

+7  A: 

This is 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);
Jason
Was just writing that. Nice.
plinth
thanks It works with minor modification for C++
Avinash