mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 17:24:26 +08:00
code refactor
This commit is contained in:
+20
-6
@@ -91,14 +91,28 @@ func WriteFile(path string, data []byte) error {
|
|||||||
|
|
||||||
// GetFileNameWithoutExtension returns the file name without extension
|
// GetFileNameWithoutExtension returns the file name without extension
|
||||||
func GetFileNameWithoutExtension(path string) string {
|
func GetFileNameWithoutExtension(path string) string {
|
||||||
fileName := filepath.Base(path)
|
if path == "" {
|
||||||
extension := filepath.Ext(fileName)
|
return ""
|
||||||
|
|
||||||
if len(extension) < 1 {
|
|
||||||
return fileName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fileName[0 : len(fileName)-len(extension)]
|
for i := len(path) - 1; i >= 0; i-- {
|
||||||
|
if path[i] == '/' || path[i] == '\\' {
|
||||||
|
path = path[i+1:]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if path == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
extension := filepath.Ext(path)
|
||||||
|
|
||||||
|
if len(extension) < 1 {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
return path[0 : len(path)-len(extension)]
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFileNameExtension returns the file extension without dot
|
// GetFileNameExtension returns the file extension without dot
|
||||||
|
|||||||
Reference in New Issue
Block a user