ruby on rails - Rename files in same path -


i trying write method rename .new file extensions new name have seen similar post nothing specific asking.

my code needs rename files in directory in. since method searching multiple directories. code have written renames files in root directory.

this function ran on multiple directories using pathname = "/path/to/app/" not work me. here code:

dotnewfiles = file.join("**", "*.new")   dir.glob(dotnewfiles).each |f|   filename = file.basename(f, file.extname(f))    #keep commented until works    #file.rename(f, filename)    print "renamed file from:\t"   printf "%-50s %s\n", f, "to".upcase + "\t" + filename end 

my output looks this:

renamed file from:  app/assets/javascripts/application.js.new     application.js   renamed file from:  app/assets/stylesheets/application.css.new     application.css 

dir.glob('**/*.new').each |f|   filename = file.expand_path('../' + file.basename(f, file.extname(f)), f)   # or   # filename = f.sub(/\.new$/, '')    file.rename(f, filename)    print "renamed file from:\t"   printf "%-50s %s\n", f, "to".upcase + "\t" + filename end 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -