From: spiralofhope Date: 2011-05-09T22:54:30+09:00 Subject: Re: Ruby Regex instead of dd, try \d\d file.replace(/\d\d\-/, '') in irb: "12-test".match(/\d\d\-/) => # On Mon, 9 May 2011 22:45:29 +0900 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 > -- http://spiralofhope.com