From: Peter Hickman Date: 2011-05-09T22:50:14+09:00 Subject: Re: Ruby Regex I think you mean file.replace(/\d\d\-/,'') rather than file.replace(/dd\-/,'') /dd\-/ will only match the character 'd' twice followed by a '-' On 9 May 2011 14:45, flebber 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() >  dir = 'C:\Users\RenshawFamily\maven\Music\Foo Fighters\Live At > Wembley Stadium' >  # add files to array unless a directoy is found >  myFiles = Array.new << File.split(dir) unless File.file?("") >  # Todo when files process step into directory and redo. >  myFiles.each do|file| >    # remove leading numbers a "-" >    file.replace(/dd\-/, '') >    Fileutils.mv(myFile, file) >  end > end > >