Way to get unique filename if specified filename already exists (.NET)

前端 未结 4 1279
醉酒成梦
醉酒成梦 2021-01-20 00:00

Is there a built in .NET function to get a unique filename if a filename already exists? So if I try and save MyDoc.doc and it already exists, the file will sav

4条回答
  •  北恋
    北恋 (楼主)
    2021-01-20 00:36

    I don't know, but it's not hard to build one yourself:

    if filename does not exists then 
        save file as filename
    else
    n = 1
    while filename(n) exists: 
        n += 1
    save file as filename(n)
    

提交回复
热议问题