I am very new to AppleScript and was hoping somebody could point me in the right direction. I have a folder that contains files with names along the lines of “4_389S.pdf”. I need code to remove all text from the “_” forward, leaving only “389S.pdf”. Any help would be much appreciated.
Thanks,
Steve
Using text item delimiters:
set myFile to "4_389S.pdf"
set TID to text item delimiters
set text item delimiters to "_"
set myFile to text item 2 of myFile
set text item delimiters to TID -- set them back to what they were ALWAYS
myFile --> "389S.pdf"
Thank you for such a quick response. How do I run the script on a folder with a bunch of files in it? Also, not all of the files are the same name? Does that change the code you gave me at all?
Thanks,
Steve
Second question first: It doesn’t matter what the names are. We’ve split the name into two parts at the underscore which is not included in either part - it’s the divider in the same way the white spaces in this sentence are dividing it into words but are not included in the words. So if we have John_Q Scrandal.abc, and run the script on it, text item 1 will be “John”, and text item 2 will be “Q Scrandal.abc” with the space and period included. If there are two underscores, then more work is required.
To answer more questions, however, calls for specifics. What are the file names actually like? Can the folder in question have folders in it with files in them? Do you want to treat every one? Does every one have an underscore in it? etc.
The folder’s name is “Uploaded Charts” and there will only be files in it. I have a group of about 500 different files that get copied to the folder every month. The number before “" correspnds to the month and the file name is after the "”. For example a few files for this month will be “4_379E.pdf”, “4_10E.pdf”, “4_361SR10”, etc… My goal is to remove whatever is before the “_”. I hope this helps. Once again thank you for all of the help.
Steve