c# Create a unique name with a GUID
Posted
by
Dave Rook
on Stack Overflow
See other posts from Stack Overflow
or by Dave Rook
Published on 2012-10-13T15:34:17Z
Indexed on
2012/10/13
15:36 UTC
Read the original article
Hit count: 206
I am creating a back up solution. I doubt there is anything new in what I'm trying to achieve.
Before copying the file I want to take a backup of the destination file in case anything becomes corrupt. This means renaming the file.
I have to be careful when renaming in case the file already exists and adding a 01 to the end is not safe.
My question is, based upon not finding the answer else where, would adding a GUID to the file name work. So, if my file was called file01.txt, renaming the file to file01.txtGUID (where GUID is the generated GUID), I could then perform my back up of that file (at this instance having 2 back ups) and then, after ensuring the file has copied (by comparing length of file to the source), delete the file with the GUID in the name.
I know the GUID is not 100% guaranteed to be unique but would this suffice?
© Stack Overflow or respective owner