Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved]Invalid characters in file name
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
Irre
Guru
Guru


Joined: 09 Nov 2013
Posts: 434
Location: Stockholm

PostPosted: Wed Mar 09, 2016 9:06 am    Post subject: [Solved]Invalid characters in file name Reply with quote

I have a "samba server" on my Raspberry. It works OK, but Windows 7 can't "read" files containing " (double quote). For example:
Quote:
/sda4/mp3/Janis Joplin - Cry Baby ("Pearl" 1971).mp3
can't be read from windows. In short, I want to rename many files. Is there any service or command to that in Linux? Invalid character " should simply be removed.

Last edited by Irre on Wed Mar 09, 2016 12:01 pm; edited 1 time in total
Back to top
View user's profile Send private message
Tatsh
Apprentice
Apprentice


Joined: 22 Jul 2007
Posts: 187

PostPosted: Wed Mar 09, 2016 11:08 am    Post subject: Reply with quote

Well, Windows has a stupid limitation yet somehow can see the filename but refuses to read such files that have characters like: | \ / and a few more. Also you cannot have a file named NUL or CON or COM1-9, etc. Ridiculous stuff. See https://msdn.microsoft.com/en-us/library/aa365247.aspx (it's amazing to me that with the dropping of DOS with NT the limitation remained and still remains).

But since we have that official documentation, you can fix your filenames with a bit of Bash on the server:

Code:

cd /sda/mp3

for i in *.mp3; do
    name=$(sed -r -e 's#[<>\:"/\\\|\?\*]##g' <<< "$i")
    echo mv -v "$i" "$name"
done


Once you are sure, remove the echo part.

Meanwhile in the sane world, /, ., .. are the only 'reserved' filenames.
Back to top
View user's profile Send private message
Irre
Guru
Guru


Joined: 09 Nov 2013
Posts: 434
Location: Stockholm

PostPosted: Wed Mar 09, 2016 12:03 pm    Post subject: Reply with quote

Thank you Tatsh!
Your command is perfect to correct invalid Windows file names! :D
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Wed Mar 09, 2016 12:18 pm    Post subject: Re: [Solved]Invalid characters in file name Reply with quote

Irre wrote:
In short, I want to rename many files. Is there any service or command to that in Linux? Invalid character " should simply be removed.

Irre ... many :) ... so to add to the suggestion by Tatsh, you could use rename.pl

Code:
# rename -n 's/"//' *.mp3 # the -n is "no action", just print what would be done

or ... rename resursively (using bash ... untested)

Code:
# shopt -s globstar
# rename -n 's/"//' **/*.mp3

or (my prefered method) using zsh ..

Code:
# autoload -Uz zmv
# zmv '**/*.mp3' '$f:gs/"/'

HTH & best ... khay
Back to top
View user's profile Send private message
Irre
Guru
Guru


Joined: 09 Nov 2013
Posts: 434
Location: Stockholm

PostPosted: Wed Mar 09, 2016 8:18 pm    Post subject: Reply with quote

khayyam, thank you too. :D
I think I have to learn some zsh and Perl 8O
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum