navigation
 Friday, March 27, 2009

This helper will do the trick:

    public static class FileHelper
    {
        public static void MoveWithOverwrite(string sourceFileName, string targetFileName)
        {
            if (File.Exists(targetFileName))
            {
                if ((File.GetAttributes(targetFileName) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    File.SetAttributes(targetFileName, FileAttributes.Normal);
                File.Delete(targetFileName);
            }
            File.Move(sourceFileName, targetFileName);
        }
    }

 

 | 
Friday, March 27, 2009 6:53:15 PM UTC
FileInfo.CopyTo supports an overwrite param so this can be reduced to:

public static void MoveWithOverwrite(string sourceFileName, string targetFileName)
{
FileInfo s = new FileInfo(sourceFileName);
if (File.Exists(targetFileName))
File.SetAttributes(targetFileName, FileAttributes.Normal);
s.CopyTo(targetFileName, true);
}

:-)
Saturday, March 28, 2009 3:23:50 PM UTC
This one works for me:

public static void MoveWithOverwrite(string sourceFileName, string targetFileName)
{
// Open your IM window:
// Lino: Hey John, delete this damn file
// John: done boss.
}

:)
Saturday, March 28, 2009 3:31:40 PM UTC
Thanks Steve, at least someone reads my blogs!

I did consider doing that, but then you would also have to add a line to Delete the original file, so not much gained in lines of code, and my code does less work when nothing needs doing ;-)

Cheers
John
john
Saturday, March 28, 2009 3:34:40 PM UTC
Thanks Lino...

Although in reality it is more like...

Open IM window to John
Lino: boss, can you delete the damn file?
Lino: hello?
Lino: John, are you there?
Lino: John?
John: Hi boss?
Lino: Can you delete the damn file?
John: Which file
Lino: The damn file
Lino: Hello?
Lino: John, you there?
Lino: John, did you delete the file?
John: I am away from my computer
Lino: Aargh! I guess I will do it myself then.
John: Back!
John: I deleted it boss
Lino: That's the wrong file boss, I already deleted it
John: Shoot
Lino: Can you undelete it please?
Lino: John?
Lino: You there?
....
john
Thursday, June 25, 2009 7:03:56 PM UTC
Good morning. College isn't the place to go for ideas. Help me! Could you help me find sites on the: Rx free shipping cialis. I found only this - Cialis tablet. They all work in the same manner to produce an erection but what does vary is the amount of time that they work for and how quickly they work. Being a high class company, our team of doctors is always looking for ways to make a better product. Thank :-) Ananda from Greece.
Comments are closed.