If I have a folder that’s a mix of files with extensions and some without extensions, how would I script adding a specific file extension to the files with no extension? I want to leave the other files alone…
thanks!
Hi,
if the files have really no extension (not only hidden), try this
property newExtension : "ext" -- without dot !
set theFolder to choose folder
tell application "Finder" to set name extension of (files of theFolder whose name extension is missing value) to newExtension
thanks, i’ll try it!
Hi StefanK,
I tried this script but couldn’t get it works.
I received an error message as:
Please advise. Thanks!
The error suggests that the file already has an extension.
Check the “Info” window by pressing Cmd+I when the file is selected in finder to see if there is an extension.
This script worked great for me!
Since I always use it for the same folder, I modified the script to this:
property newExtension : "ext"
set theFolder to alias "Macintosh HD:Users:username:Desktop:folder:PDFs:"
tell application "Finder" to set name extension of (files of theFolder whose name extension is missing value) to newExtension
In the event I ever need it for a random folder or random extension I made this version:
set thedata to text returned of (display dialog "choose an extension with NO PERIOD eg: pdf" default answer " ")
set theFolder to choose folder
tell application "Finder" to set name extension of (files of theFolder whose name extension is missing value) to thedata
Just be carefully blindly putting extensions on files. I found out the hard way a couple years ago that the Finder is a little brain-dead in this area if the resource fork is missing (and sometimes even when it exists).
For example, it’s horrible at telling an Illustrator CS4 file from an Acrobat file without the extension or resource information.nothing more confusing than a PDF file labelled as AI or AI files as a PDF. eeek