C#: How would you make a unique filename by adding a number?

前端 未结 18 820
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 11:46

I would like to create a method which takes either a filename as a string or a FileInfo and adds an incremented number to the filename if the file

18条回答
  •  天涯浪人
    2020-11-27 12:01

    If checking if the file exists is too hard you can always just add a date and time to the file name to make it unique:

    FileName.YYYYMMDD.HHMMSS

    Maybe even add milliseconds if necessary.

提交回复
热议问题