I need a scrip to replace .png with @2x.png How can I do this for all file names in a directory?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming bash:
Explanation:
Line 1:
For loop. Iterates over all filenames in the current directory that match the glob pattern
*.png, sets$fto each name in turn, and executes the body of the loop.Line 2:
Executes the
mvtool. The first arg is just"$f", which is the file you want to rename. The second arg is a two-step process:${f%.png}evaluates to the filename with the extension.pngstripped off.Following the stripped filename is
@2x.png, which just appends that string back onto the filename.Line 3:
Terminates the for loop.