Use 'safe' filenames on all operating systems

This commit is contained in:
Al Beano 2017-08-19 12:38:48 +01:00
parent c89e0cd4c0
commit f1fc0cef54
3 changed files with 12 additions and 17 deletions

View File

@ -6,11 +6,6 @@ import(
"path"
)
func SanitiseFilename(filename string) (newName string, e error) {
newName = filename
return
}
func DirOf(filename string) (dirname string, e error) {
dirname = path.Dir(filename)
return

View File

@ -6,16 +6,6 @@ import(
"regexp"
)
func SanitiseFilename(filename string) (newName string, e error) {
r, e := regexp.Compile("[\\?<>:/\"\\\\|\\*]")
if e != nil {
return
}
newName = r.ReplaceAllString(filename, "")
return
}
func DirOf(filename string) (dirname string, e error) {
r, e := regexp.Compile(`\\[^\\]+$`)
if e != nil {

View File

@ -15,6 +15,16 @@ import (
"strings"
)
func SanitiseFilename(filename string) (newName string, e error) {
r, e := regexp.Compile("[\\?<>:/\"\\\\|\\*]")
if e != nil {
return
}
newName = r.ReplaceAllString(filename, "")
return
}
func main() {
if len(os.Args) != 2 {
fmt.Printf("Usage: %s <wimp id or url>\n", os.Args[0])
@ -68,7 +78,7 @@ func main() {
}
dirName := album.Artist+" - "+album.Title+" ("+fmt.Sprintf("%d", album.Year)+") [WEB FLAC]"
dirName, e = platform.SanitiseFilename(dirName)
dirName, e = SanitiseFilename(dirName)
if e != nil {
panic(e)
}
@ -90,7 +100,7 @@ func main() {
fmt.Printf("[%d/%s] %s...", track.Volume, num, track.Title)
var filename = fmt.Sprintf("%s - %s.flac", num, track.Title)
filename, e = platform.SanitiseFilename(filename)
filename, e = SanitiseFilename(filename)
if e != nil {
panic(e)
}