another script question

Tom Metro blu at vl.com
Thu Jan 26 16:59:06 EST 2006


gboyce wrote:
> matt nicholson wrote:
>> many of them are too long for the xbox filesystem.
>> theres alot of them and the are all spread out across
>> my /path/artist/album/track style directories.
>> 
>> does anyone know of a quick script or something to just walk through a
>> directory recursively, and remove any "trailing" characters off the end
>> of the files (not the directories?)
> 
> According to the documentation I've found, the fatx filesystem used by 
> the xbox supports filenames of 42 characters...

Assuming files with an .mp3 extension, and a length limit of 42 
characters (including the extension), this should do it:

find . -name "*.mp3" | rename -v \
's|(.*/)(.*)(\.mp3)|$1 . substr($2,0,38) . $3|e'


providing you find yourself a copy of the previously mentioned 'rename' 
Perl script.

If you can't find the script or don't have Perl on the box, you might 
want to investigate 'awk'. It's the next best tool for this kind of 
string manipulation. You could pipe the output of 'find' to it.

'find' itself supports a printf action in which you can specify the 
formatting of file names and paths, including their widths, but like the 
C printf() it doesn't truncate strings that exceed the specified width, 
it only pads the fields with spaces.

  -Tom

-- 
Tom Metro
Venture Logic, Newton, MA, USA
"Enterprise solutions through open source."
Professional Profile: http://tmetro.venturelogic.com/



More information about the Discuss mailing list