Escape slashes from file path

75 views
Skip to first unread message

Anik Hasibul

unread,
Oct 20, 2018, 1:21:55 PM10/20/18
to golang-nuts
```
{
"name":"foo/bar.mp3",
"url":"https://foobar.com/bar.mp3"
}
```

I wanna save the song after fetching the url.

When I am going to save the file to the `name` value it says `open: foo/bar.mp3 no such....`, because the directory `foo` doesn't exist.

I wanna save it in the current directory.
Any way to escape it?

Please don't suggest `url.PathEscape`, it encodes unicode char (my language is Bangla).

Tamás Gulácsi

unread,
Oct 20, 2018, 2:00:08 PM10/20/18
to golang-nuts
Use filepath.Base to strip the directory part.

Anik Hasibul

unread,
Oct 20, 2018, 2:06:55 PM10/20/18
to golang-nuts, Tamás Gulácsi
I need the whole name :( the slash isn't separating the directory. It's "artist/track.mp3"

From: golan...@googlegroups.com <golan...@googlegroups.com> on behalf of Tamás Gulácsi <tgula...@gmail.com>
Sent: Sunday, October 21, 2018 12:00:08 AM
To: golang-nuts
Subject: [go-nuts] Escape slashes from file path
 
Use filepath.Base to strip the directory part.

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/OYUc8qkAogM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tamás Gulácsi

unread,
Oct 20, 2018, 2:12:13 PM10/20/18
to golang-nuts
strings.Replace(fn, "/", "-", -1) ?

You can use other transcodings (quopri, base64) but those needs decoding, too.

Anik Hasibul

unread,
Oct 20, 2018, 2:20:41 PM10/20/18
to golang-nuts, Tamás Gulácsi
Yes! Just tried.
Thanks for giving me the idea about kicking the slashes from file name.

Sent: Sunday, October 21, 2018 12:12:13 AM
To: golang-nuts
Subject: Re: [go-nuts] Escape slashes from file path
 
strings.Replace(fn, "/", "-", -1) ?

You can use other transcodings (quopri, base64) but those needs decoding, too.

Reply all
Reply to author
Forward
0 new messages