Re: Script to strip illegal characters from files and directories?
- From: Dave B <daveb@xxxxxxxxxxxx>
- Date: Sat, 10 May 2008 12:13:49 +0200
On Saturday 10 May 2008 11:56, Janis Papanagnou wrote:
No need to handle / in filenames; that's an illegal character in Unix
filenames. With ksh93 or bash you may want to try...
find . | while read -r f ; do mv -i "${f}" "${f//[:;*?\"<>|]}" ; done
where the characters are removed (as you seem to like) or try
find . | while read -r f ; do mv -i "${f}" "${f//[:;*?\"<>|]/_}" ; done
to replace the characters by an _ (which I think is better).
The script will try to do "mv . ." first, which of course will fail.
You should at least check that the new name differs from the old name, and
probably use "--" to indicate the end of the options to mv.
Furthermore, if a directory with strange characters is encountered first
(and find by default output directories first), then renaming the files
inside the directory will fail.
If the structire is as follows:
dir<>foo
|
+------file1**?
\------file:2:bar
Then "dir<>foo" will be renamed first, and subsequent attempts to
rename './dir<>foo/file1**?' and './dir<>foo/file:2:bar' to something else
will fail, since directory 'dir<>foo' does not exist anymore.
--
D.
.
- Follow-Ups:
- Re: Script to strip illegal characters from files and directories?
- From: Janis Papanagnou
- Re: Script to strip illegal characters from files and directories?
- References:
- Script to strip illegal characters from files and directories?
- From: somebody
- Re: Script to strip illegal characters from files and directories?
- From: Janis Papanagnou
- Script to strip illegal characters from files and directories?
- Prev by Date: Re: Script to strip illegal characters from files and directories?
- Next by Date: Re: Can it be done with *sed* ?
- Previous by thread: Re: Script to strip illegal characters from files and directories?
- Next by thread: Re: Script to strip illegal characters from files and directories?
- Index(es):
Relevant Pages
|