UweKeim / ZetaLongPaths

A .NET library to access files and directories with more than 260 characters length.
https://nuget.org/packages/ZetaLongPaths
MIT License
142 stars 28 forks source link

Added ZlpFileInfo.OpenCreate() for consistency with File.Create() #11

Closed DizzyHSlightlyVoided closed 8 years ago

DizzyHSlightlyVoided commented 8 years ago

The .Net library has the method System.IO.File.Create(), which is like File.OpenWrite() (and hence ZlpFileInfo.OpenWrite()) except that if the file already exists, it is truncated to zero bytes. If you do something like this:

    using (FileStream fs = new ZlpFileInfo("Lalala.txt").OpenWrite())
    using (StreamWriter sw = new StreamWriter(fs))
    {
        sw.WriteLine("AAAAAAAAAAAAAAAAAAAA");
    }
    using (FileStream fs = new ZlpFileInfo("Lalala.txt").OpenWrite())
    using (StreamWriter sw = new StreamWriter(fs))
    {
        sw.WriteLine("BBBBB");
    }

... Lalala.txt has the following contents:

BBBBB
AAAAAAAAAAAAA

Whereas with my addition, if you replace OpenWrite() with OpenCreate(), Lalala.txt contains only BBBBB.

UweKeim commented 8 years ago

Thanks a lot!

DizzyHSlightlyVoided commented 8 years ago

No problem!