mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 If a file with the same name exists during export PDF/Docx, it will be automatically renamed https://github.com/siyuan-note/siyuan/issues/11357
This commit is contained in:
parent
abf92b602c
commit
749ed8a4ac
4 changed files with 36 additions and 19 deletions
|
|
@ -24,6 +24,7 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
|
|
@ -34,6 +35,24 @@ import (
|
|||
"github.com/siyuan-note/logging"
|
||||
)
|
||||
|
||||
func GetUniqueFilename(filePath string) string {
|
||||
if !gulu.File.IsExist(filePath) {
|
||||
return filePath
|
||||
}
|
||||
|
||||
ext := filepath.Ext(filePath)
|
||||
base := strings.TrimSuffix(filepath.Base(filePath), ext)
|
||||
dir := filepath.Dir(filePath)
|
||||
i := 1
|
||||
for {
|
||||
newPath := filepath.Join(dir, base+" ("+strconv.Itoa(i)+")"+ext)
|
||||
if !gulu.File.IsExist(newPath) {
|
||||
return newPath
|
||||
}
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
func GetMimeTypeByExt(filePath string) (ret string) {
|
||||
ret = mime.TypeByExtension(filepath.Ext(filePath))
|
||||
if "" == ret {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue