View previous topic :: View next topic |
Author |
Message |
Irre Guru
Joined: 09 Nov 2013 Posts: 434 Location: Stockholm
|
Posted: Wed Mar 09, 2016 9:06 am Post subject: [Solved]Invalid characters in file name |
|
|
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 |
|
|
Tatsh Apprentice
Joined: 22 Jul 2007 Posts: 187
|
Posted: Wed Mar 09, 2016 11:08 am Post subject: |
|
|
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 |
|
|
Irre Guru
Joined: 09 Nov 2013 Posts: 434 Location: Stockholm
|
Posted: Wed Mar 09, 2016 12:03 pm Post subject: |
|
|
Thank you Tatsh!
Your command is perfect to correct invalid Windows file names! |
|
Back to top |
|
|
khayyam Watchman
Joined: 07 Jun 2012 Posts: 6227 Location: Room 101
|
Posted: Wed Mar 09, 2016 12:18 pm Post subject: Re: [Solved]Invalid characters in file name |
|
|
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 |
|
|
Irre Guru
Joined: 09 Nov 2013 Posts: 434 Location: Stockholm
|
Posted: Wed Mar 09, 2016 8:18 pm Post subject: |
|
|
khayyam, thank you too.
I think I have to learn some zsh and Perl |
|
Back to top |
|
|
|