0

I have a large number of image files in my project but all of them have spaces in them which was causing issues on github. I need to change them all using rails console and add '-' instead of a spaces. I know it is possible but can't get it. Used this to move and change a single filename:

cd app/assets/images && mv avatar.png avatar123.png

ARK
  • 772
  • 7
  • 21
  • 1
    Define "can't get it". What did you try already? The types of files isn't relevant. Your example doesn't encapsulate the problem, btw. Renaming a file is a one-liner: https://stackoverflow.com/questions/5530479/how-to-rename-a-file-in-ruby. Changing directories and iterating over files is similarly well-documented in both the Ruby docs and elsewhere. Please be specific with the problem(s) you're having. – Dave Newton Dec 19 '18 at 15:58
  • @DaveNewton I found the answer after 2 hours search and it works perfectly but haven't figured out how it does work, yet. – ARK Dec 19 '18 at 16:19
  • 1
    Everything in your answer has `man` docs. But this has nothing to do with the Rails console--your example and your answer is a shell script. – Dave Newton Dec 19 '18 at 16:22
  • @DaveNewton I totally understand what you meant back then but I was very new to the concept. Sorry for making you want to hit a wall. – ARK Apr 11 '19 at 17:06

1 Answers1

0

Okay I managed to solve the issue with this 2nd script on this page: Source

My current script goes like this and it worked 100% :
cd app/assets/images && for f in * ; do mv "$f" $( echo $f | tr ' ' '-' ) ; done

ARK
  • 772
  • 7
  • 21