File path conversions - Windows to Linux +GRAMPS
Jon Cosby
jon.l.cosby at gmail.com
Thu Jul 8 03:49:20 UTC 2010
On Wed, Jul 7, 2010 at 5:27 PM, NoOp <glgxg at sbcglobal.net> wrote:
<snip>
Unfortunately the spaces, commas,
> periods, # signs et all are creating issues. My system reads them
> properly, i.e.:
>
> /home/<username>/<somename>_xml.gpkg.media/My Documents/My
> Pictures/<surname> Geneology/<surname>, <firstname>
> <middleinitial>/<sirname>, <firstname> <middleinitial>. Certificate of
> Birth.jpg
>
> But I'd like to figure out a way to clean all those up to no spaces,
> periods, commas, etc.
>
> Any suggestions on how I can batch convert all of those to
> path/filenames? Or am I doomed to having to go through each one
> individually?
>
>
>
>
I'm not sure about Bash, but this would be fairly easy in Python:
import os
SPACE = " "
COMMA = ","
PATH = "/path/to/files"
for filename in os.listdir(PATH) :
os.rename(filename, filename.replace(SPACE, "_").replace(COMMA, "_"))
This would replace all spaces and commas with underscores (_).
Jon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20100707/73540aea/attachment.html>
More information about the ubuntu-users
mailing list