Skip to content

Instantly share code, notes, and snippets.

@ruvasik
Last active December 26, 2016 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruvasik/fcc90970a6aaf3a9de780788958cd6de to your computer and use it in GitHub Desktop.
Save ruvasik/fcc90970a6aaf3a9de780788958cd6de to your computer and use it in GitHub Desktop.
Renaming files (jpg) in the folders to sequential numbers order starting with 1 in every folder
set text item delimiters to "."
tell application "Finder"
set the_folder to choose folder
set the_subfolders to every folder in the_folder
repeat with index from 1 to the count of the_subfolders
set this_folder to item index of the_subfolders
set img_files to (every file in this_folder whose name ends with ".jpg")
repeat with indexf from 1 to (the count of img_files)
set this_file to item indexf of img_files
set file_name_count to text items of (get name of this_file)
if number of file_name_count is 1 then
set file_extension to ""
else
set file_extension to "." & item -1 of file_name_count
end if
set the name of this_file to indexf & file_extension as string
end repeat
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment