Automator: Create folder from suffix of filename and put file names with same suffix into folder

I've been using a script to use automator to create a folder from the filename and put that file into it the folder just created.
I have a bunch of files that have similar names to them, but I don't want every file to be put into its own folder, instead I want all files with the same suffix (001) to go into the same folder.  I would also like the folder name to just be named the same as the suffix (001) instead of the full file name.
For example all of these files names that end with the same integer (001) should be dumped into the same folder named "001":
Boston_ProRes422_1920x1080_24p_Audio_001
Boston_ProRes422_3840x2160_24p_Audio_001
Boston_ProRes422_3840x2160_24p_RAW_Audio_001
Boston_ProRes422_1920x1080_24p_Audio_002
Boston_ProRes422_1920x1080_24p_Audio_005
Boston_ProRes422_1920x1080_24p_Audio_010
Any help at all would be incredible!!
Thanks!
Here's the script I'm using right now:
on run {input, parameters} -- create folders from file names and move
  set output to {} -- this will be a list of the moved files
  repeat with anItem in the input -- step through each item in the input
  set {theContainer, theName, theExtension} to (getTheNames from anItem)
  try
  set destination to (makeNewFolder for theName at theContainer)
  tell application "Finder"
  move anItem to destination
  set the end of the output to the result as alias -- success
  end tell
  on error errorMessage -- duplicate name, permissions, etc
  log errorMessage
  # handle errors if desired - just skip for now
  end try
  end repeat
  return the output -- pass on the results to following actions
end run
to getTheNames from someItem -- get a container, name, and extension from a file item
  tell application "System Events" to tell disk item (someItem as text)
  set theContainer to the path of the container
  set {theName, theExtension} to {name, name extension}
  end tell
  if theExtension is not "" then
  set theName to text 1 thru -((count theExtension) + 2) of theName -- just the name part
  set theExtension to "." & theExtension
  end if
  return {theContainer, theName, theExtension}
end getTheNames
to makeNewFolder for theChild at theParent -- make a new child folder at the parent location if it doesn't already exist
  set theParent to theParent as text
  if theParent begins with "/" then set theParent to theParent as POSIX file as text
  try
  return (theParent & theChild) as alias
  on error errorMessage -- no folder
  log errorMessage
  tell application "Finder" to make new folder at theParent with properties {name:theChild}
  return the result as alias
  end try
end makeNewFolder

Thanks Neil for the response! That script didn't work, but I did get it to work with my old script by changing "set TheName to" numbers different.  Here's my final script which creates folders named "001", "002", and so forth and dumps in the files that end in that same suffix in the matching folder.
on run {input, parameters} -- create folders from file names and move
  set output to {} -- this will be a list of the moved files
  repeat with anItem in the input -- step through each item in the input
  set {theContainer, theName, theExtension} to (getTheNames from anItem)
  try
  set destination to (makeNewFolder for theName at theContainer)
  tell application "Finder"
  move anItem to destination
  set the end of the output to the result as alias -- success
  end tell
  on error errorMessage -- duplicate name, permissions, etc
  log errorMessage
  # handle errors if desired - just skip for now
  end try
  end repeat
  return the output -- pass on the results to following actions
end run
to getTheNames from someItem -- get a container, name, and extension from a file item
  tell application "System Events" to tell disk item (someItem as text)
  set theContainer to the path of the container
  set {theName, theExtension} to {name, name extension}
  end tell
  if theExtension is not "" then
  set theName to text -5 thru -((count theExtension) + 4) of theName -- just the name part
  set theExtension to "." & theExtension
  end if
  return {theContainer, theName, theExtension}
end getTheNames
to makeNewFolder for theChild at theParent -- make a new child folder at the parent location if it doesn't already exist
  set theParent to theParent as text
  if theParent begins with "/" then set theParent to theParent as POSIX file as text
  try
  return (theParent & theChild) as alias
  on error errorMessage -- no folder
  log errorMessage
  tell application "Finder" to make new folder at theParent with properties {name:theChild}
  return the result as alias
  end try
end makeNewFolder

Similar Messages

  • Folder Shares cant log in and put files

    Might be a stupid question, but I am restoring a heap of files back from an old server to a new server, into a shared folder thats within the OSX server "Groups" folder ... when I log in as an admin on the machine to dump the files back into Groups/group name/shared folder All I see inside the Groups folder are all the group names BUT with a red icon on the folder , wont let me into the group names and their contained shared folders ??
    all I want to do is put back all the users shared files from an old server onto the new server and their new shared folder inside their group name

    Have you checked the permissions? Sometimes you will need to change the permissions to let you see something and work with it, and then change it back so that your users can use it.
    It might be easiest to do this in Terminal. If you are not familiar with Terminal and command line functions like sudo, chown, and chmod, now is the time to read up on them and learn how they work. Used properly, those tools will greatly speed up the process, though they should be used with care.
    Good luck!

  • How do i get a list of file names in to a new folder?

    Hi,
    Does anyone know if there is a way of having a list of  image file names, searching for the images then putting them into a new folder?  I'm guessing it can probably be done through mac scripting but I know nothing about scripting and genreally not great with technogy so ideally need step by step instructions!!
    If anyone can help I would really appreciate it!!
    Ruth

    Without details about your workflow and folder set up, I can only give you a generic script, but this should at least get us started.  test it and see what needs to be tweaked.
    -- set paths to source and destination folders
    set imageSourcePath to POSIX path of (choose folder with prompt "Choose a source folder.")
    set destinationFolder to POSIX file POSIX path of (choose folder with prompt "Choose a destination folder.")
    -- get file names from text file: assumes one name per line.
    set fileNameTextFile to (choose file with prompt "Choose a file list text file." of type "public.plain-text")
    set fileNames to paragraphs of (read fileNameTextFile)
    repeat with thisFileName in fileNames
      -- replace each file name with an alias to that image file
              set contents of thisFileName to POSIX file (imageSourcePath & thisFileName)
    end repeat
    tell application "Finder"
      -- using 'duplicate' because I assume you want to make copies rather than move files
      duplicate fileNames to destinationFolder
    end tell

  • Trying to write an Automator program to find files with same time created and change file names to matching source folder names

    I am failrly green when it comes to automator.
    I am trying to write an Automator program:
    Not sure where to post this
    trying to write an Automator program to find files and alter their names
    I have a source folder with correct named master files in it.
    eg. A0001_1234.mpeg
    time created 14:02:03
    date 07/07/2012
    Another folder where there will be copies of the master files in a different format with different names but created at the same time as a file in the source directory.
    they are created with a seperate device but they are
    A0000001.mp4
    time created 14:02:03
    date 07/07/2012
    I need it to then take the name from the source fies and apply the correct name to the matching file based on the time it was created.
    I can't seem to find actions in automator that reference time crated.
    Is this something I will be able to Do in automator?
    Any help would be great
    Thanks
    R

    Hi,
    It's impossible to do this without any script in Automator.
    Use this AppleScript script :
    set source to choose folder with prompt "Select the source folder"
    set anotherfolder to choose folder with prompt "Choose the another folder"
    tell application "Finder"
        repeat with tfile in (get files of source)
            set cDate to creation date of tfile
            set findFiles to (files of anotherfolder whose creation date is cDate)
            if findFiles is not {} then
                set tName to name of tfile
                set name of item 1 of findFiles to tName
            end if
        end repeat
    end tell

  • I created a folder from my camera roll and shared with my icloud acct, can't figure out how to access it from my computer?

    I created a folder from my camera roll and shared with my icloud acct, can't figure out how to access it from my computer? I log onto icloud and can't find anywhere where "shared" photos are..

    You need Mountain Lion (10.8.2 or higher) and iPhoto '11 (9.4 or higher) or Aperture 3.4 to get shared photo streams on Mac.
    Another option to transfer them is to either import them to iPhoto using your usb cable, as explained here:http://support.apple.com/kb/HT4083, or to us an app like PhotoSync to transfer them to your Mac over your wifi.  (PhotoSync will also transfer albums, not just photos from the camera roll.)

  • I got some books from the itunes store and put them into my library.  I created a playlist so that I could burn them to cds.  The title is there but no contents.  It won't even play the playlist.  How do I get the contents of the book?

    I got some books from the itunes store and put them into my library.  I created a playlist so that I could burn them to cds.  It won't even play the book, there are no contents.  How do I get the contents of the book?

    I'm guessing this is a problem unique to me as there have been no replies at all...  Thanks a bunch folks

  • Hi thee.  As logical as I can be.  I export a file back into my folder as a PSD.  I then export that file to PS.  Work on it, save and return it to LR.  The file goes to the bottom of the folder from where I have to put it back in the original place, taki

    Hi thee.  As logical as I can be.  I export a file back into my folder as a PSD.  I then export that file to PS.  Work on it, save and return it to LR.  The file goes to the bottom of the folder from where I have to put it back in the original place, taking time and driving me slightly mad.  Why does the file not go back to where it came from please?  Thanks  Tim

    Umm, but this folder is an amalgam of two cameras and five cards, and I want them in capture order!  Thanks for trying though Jim.
    Cheers
    Tim

  • If I move a mailbox from my imap account to "on my mac" can I safely delete the folder from the mail server and still be able to read the messages?

    If I move a mailbox from my imap account to "on my mac" can I safely delete the folder from the mail server and still be able to read the messages?

    You certainly can.
    Be aware that the emails you move to local storage ("on my Mac") will be the only copies that remain.

  • File name with symbols won't delete from trash.cache\trash\cache folder.

    found this weird file name with symbols (squares nad the like) in the trash.cache\trash\cache folder. Can't seem to delete it from windows, can't get at from the dos prompt. Windows safe mode won't delete it.
    Any suggestions as to what it is and how to get rid of it.
    At present am trying reinstall of firefox and virus scan.
    Thanks
    Peter

    I tried to do the instructions Adobe gave me but when
    I put in the disc that came with my mac and hold down
    C when it restarts it takes me to the screen to do a
    fresh install.
    At that point go to the Menu & select Disk Utility - I can't remember exactly which menu but you should be able to find it easily... there isn't too much there
    I went into the disk utility through the Apps folder
    and for somereason the option to repair isnt
    highlighted and it wont let me click it. I tried to
    repair permissions/verify but it doesnt change
    anything. I looked at the info and it says the volume
    can be repaired, but it wont let me.
    You can't Repair the disk the system is currently running the OS from - That's why you have to boot from the Installer disk (or some other start-up disk). Repair Disk addresses directory structure issues - totally separate from what Repair Permissions does.
    HTH|:>)
    Bob J.

  • I can not transfer date from one hard drive to another, I keep getting an error because I have two of the same file names and one file name is in caps and I cant change the file name

    can not transfer date from one hard drive to another, I keep getting an error because I have two of the same file names and one file name is in caps and I cant change the file name. My original external has an error and needs to be reformatted but I dont want to lose this informations its my entire Itunes library.

    Sounds like the source drive is formatted as case sensitive and the destination drive is not. The preferred format for OS X is case insensitive unless there is a compelling reason to go case sensitive.
    Why can't you change the filename? Is it because the source drive is having problems?  If so is this happening with only one or two or a few files? If so the best thing would be to copy those over individually and then rename them on the destination drive.
    If it is more then you can do manually and you can't change the name on the source you will have to reformat the destination as case sensitive.
    Btw this group is for discussion of the Support Communities itself, you;d do better posting to Lion group. I'll see if a host will move it.

  • Can I move all my photo that I can see on iPhoto from my Mac hardrive and put them on an external hard drive and still be able to see them as thumbnails in iPhoto? Thanks! The reason, I need to know if I can do this is b/c I am running out of HD space!sp

    can I move all my photo that I can see on iPhoto from my Mac hardrive and put them on an external hard drive and still be able to see them as thumbnails in iPhoto? Thanks! The reason, I need to know if I can do this is b/c I am running out of HD space!sp

    Make sure the drive is formatted Mac OS Extended (Journaled)
    1. Quit iPhoto
    2. Copy the iPhoto Library from your Pictures Folder to the External Disk.
    3. Hold down the option (or alt) key while launching iPhoto. From the resulting menu select 'Choose Library' and navigate to the new location. From that point on this will be the default location of your library.
    4. Test the library and when you're sure all is well, trash the one on your internal HD to free up space.
    Regards
    TD

  • Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.

    Hello,
    I have gone through couple of posts regarding this issue but couldn't get the right solution. Could you please help what exactly we are missing here.
    Details:
    1) we have two SQL instances on one standalone machine (Default Instance (2008 SP3) + Named Instance (SQL 2012 SP1))
    2) Both instances are configured to accept SQL+ Windows authentication.
    3) when we give access to our users they are getting following exception if they connect with 'windows authentication'. (For both instances)
    Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.
    Note: (Being a sys + windows admin I'm able to connect both the instances from same client machine without
    any issues)
    4) Also, we observed following error in windows application event log,
     SSPI handshake failed with error code 0x8009030c, state 14 while establishing a connection with integrated security; the connection has been closed. Reason: AcceptSecurityContext failed. The Windows error code indicates the cause of failure.
    The logon attempt failed   [CLIENT: 192.168.xxx.xyx]
    5) If we create SQL login it is working fine without any issues.
    Could someone guide/help  me identifying and fixing this issue.
    Thank you

    Hello,
    Are those Windows Logins associated to domain Windows accounts? Windows Logins work for domain accounts and local Windows account created on the server where the SQL Server instance is installed (and used to login locally to the server).
    Could you try to delete one of the Windows logins that fail to login , and try to recreate them?
    The following resources may help:
    http://blogs.msdn.com/b/dataaccesstechnologies/archive/2012/12/19/error-message-quot-login-failed-the-login-is-from-an-untrusted-domain-and-cannot-be-used-with-windows-authentication-quot.aspx
    http://support.microsoft.com/kb/555332
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • I have an IMac.  I put a folder on the desk top and now want to delete it.  The folder seems to be locked.  I went to get info and tried to unlock it but still can't delete it.  The folder has nothing in it.  Any help would be great.  Thanks

    I have an IMac.   I put a folder on the desk top and now want to delete it.  The folder seems to be locked.  I went into Get Info and attemted to unlock the folder and delete it.  Won't go away.   There is nothing in the folder.   How do I unlock this folder and delete it?   When I try to delete it, I'm asked for my password which I put in and is accepted, but will not delete the folder.  Any help would be great.

    If you are sure there is nothing in it, download trashit, a useful free app.   That will dispose of it.
    Download Trash It! for Mac - Force-empty your trash can. MacUpdate.com

  • Lost home PC with my iTunes account on it in a home fire.  How can I take everything from my iPhone 4 and put it on my new PC?

    Lost home PC with my iTunes account on it in a small home fire.  How can I take everything from my iPhone 4 and put it on my new PC?  Is this even possible?  iPhone 4 / new PC running Win XP Pro.  I have backed up to iCloud recently so the info is out there, just need to bring it down onto my PC....
    Need HELP.............

    Copy from iPod to computer
    Recovering your iTunes library from your iPod or iOS device: Apple Support Communities
    The sync to iPhone
    iTunes: Syncing media content to iOS devices and iPod

  • My old computer crashed and needed replaced, how do i get my library back from the old one and put on the new one?i had xp now windows 7

    my old computer crashed, it was xp i replaced it with windows 7 how do i get my library back from the old computer and put on the new one?

    iDevices are not backup devices.
    Use the backup of the computer to put everything back.

Maybe you are looking for