On Mon, May 9, 2011 at 3:45 PM, flebber <flebber.crue / gmail.com> wrote: > I am new too using regex on files and I am not quite getting the > result I expect. The script currently doesn't error but also doesn't > update the file either. > > Trying to remove leading numbers and ' - 'from the start of a filename > given a directory. > > require 'fileutils' > > def cleanFiles() > ¨Âéò §ÃºÜÕóåòóÜÒåîóèá÷ÆáíéìùÜíáöåîÜÍõóéãÜÆïÆéçèôåòóÜÌéöÁô > Wembley Stadium' Better uses forward slashes to avoid potential issues with quoting. > add files to array unless a directoy is found > ¨ÂùÆéìåó Áòòáù®îå¼¼ Æéìå®óðìéô¨äéòõîìåóó Æéì宿éì忨¢¢© You are adding two elements (dirname and basename) to a new Array. What for? Also, what is the test at the end of the line supposed to do? > Todo when files process step into directory and redo. > ¨ÂùÆéìåó®åáãäïüæéìåü Here you are iterating through an Array which you know to always only contain 1 element (a nested Array with two elements, see above). It does not make any sense to use an Array. > remove leading numbers a "-" > ¨Âéìå®òåðìáã娯ääܯ§§ You rather want # all numbers yield one dash new_file = file.sub /\A\d+/, '-' or # each number gets its own dash new_file = file.sub(/\A\d+/) {|m| '-' * m.length} > ¨Âéìåõôéìó®íö¨íùÆéìåæéìå As far as I can see myFile is undefined here. > ¨Âîä > end Overall the logic is quite dark to me... Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/