Tim Churches wrote:
> Simon James wrote:
>> Can any *nix aficionados give me a command to recursively search a directory
>> structure and remove the trailing spaces from any file names? Spaces within
>> the name need to remain ideally, it is just the ones at the end I want gone.
>>
>> EG
>>
>> "Saturday Night.txt  " needs to become "Saturday Night.txt"
>>
>> A client has been fairly sloppy with the naming of files on his Mac which
>> handle them fine, but when he tries to backup these files to an SMB share
>> the process fails.
> 
> Here is a Python script (requires Python 2.3 or later to be installed -
> see http://www.python/org ) - this is untested, so test it first and
> then uncomment the os.rename() line when you are satisfied it won't eat
> all your files for breakfast. Change the value of top to wherever in
> your filesystem you want to start - it will recurse all the way down
> under that. Provided as-is, with no warranty expressed or implied,
> absolutely no responsibility for stuff-ups or mishaps accepted. 

And only work on a copy of your data, and/or take and verify a back-up
first. Precautionary principle applies!

Tim C

> #####################
> import os
> 
> top = '/home/simon'
> 
> for root, dirs, files in os.walk(top):
>     for oldname in files:
>         if oldname.endswith(' '):
>             newname = os.path.join(root, oldname.rstrip())
>           oldname = os.path.join(root, oldname)
>           try:
>                 # os.rename(oldname,newname)
>                 print 'renamed ', oldname, '->', newname
>           except:
>                 print 'Cannot rename ', oldname, ', non-unique?'
> ####################
> 
> Tim C
> 
> _______________________________________________
> Gpcg_talk mailing list
> [email protected]
> http://ozdocit.org/cgi-bin/mailman/listinfo/gpcg_talk
> 

_______________________________________________
Gpcg_talk mailing list
[email protected]
http://ozdocit.org/cgi-bin/mailman/listinfo/gpcg_talk

Reply via email to