Trying to create an Applecreate to rename files into folders based on filename

I am trying to create an AppleScript that will take a file (a.b.c.txt forexample) and create a directory from the filename minusextensionand then move the file into that directory
ie.a.b.c>a.b.c.txt
I found this script from red_menace
{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
But my problem with this script is that it does messes up if the file name includes the period, from my example, the listed script will make directorys a, b, and c instead of a.b.c

You can use this Automator Workflow:
for f in "$@"
do
  d=${f%.*}
  if [ ! -d "$d" ]; then 
       mkdir "$d"
  fi
  mv "$f" "$d"
done

Similar Messages

  • Move files into folders based on EXIF Creation Date

    Hi all,
    Being a novice with Applescript I have read what I can find on this forum, but are not able to find exactly what I'm looking for. I think that the posting "Using AppleScript to create folders and place files in them" is the closest I get to what I want but I want to create the folders based on EXIF creation date.
    Let me explain.
    I have a folder that contains thousands of jpg, mp4, mov and avi files; all created by different cameras. I want to bring some order to this and place files in folders based on year, month and date that the file was created (the photo taken or the video captured). This date is stored in the EXIF creation date.
         Take all files in folder A
          foreach file find the EXIF creation date
          move each file into directory tree (at same location is ok) where toplevel is YEAR, next directory level is named accoring to EXIF creation date as MMDDYY
          if no EXIF creation date can be found, fallback to creation date (file property?)
          if no good date is found, leave file alone in folder A for manual sorting; do not use modification date as this may have been altered
         this would create a structure as
         2002
                011602
                        File 1 taken Jan 16 2002
                        File 2 taken Jan 16 2002
                082002
                        File 1 taken Aug 20 2002
                        File 2 taken Aug 20 2002
          2003
                 etc 
         2004
             |   etc
         2014
                 010114
                        File 1 taken Jan 1 2014
    etc etc

    Well, technically that's correct, Frank, but the same could be said of much of AppleScript - the core functionality is limited, but there's a lot you can do.
    For example, it's actually trivial to use Image Events get any given EXIF tag of an image:
    set theFile to (choose file)
    tell application "Image Events"
              set f to open theFile
              set cD to value of metadata tag "CreationDate" of f
      close f
    end tell
    Now, cD will have the value of the CreationDate tag (assuming it exists, of course - you'll need to wrap this in a try/end try statement). Once you have that it shouldn't be too hard to extract the date components, work out the target directory name and move the file.

  • Script/Automator Get Filenames in Folder and Move Each File into Folder based on Filename?

    I have searched for an answer to this and I have searched through multiple file renaming apps on the app store too but alas I cannot find anything that does what I want so I ended up looking into Automator as my saviour but I am a total NOOB.
    What I want to do is point automator to a folder of my choosing
    Automator then takes each file in that folder and creates a folder with the same name as the file and then move the file into that subfolder.
    Sounds easy enough eh
    I'm totally stumped, anyone have any guidance ???

    This is a PITA to do in automator - automator does not handle loops the way it should - but in applescript it looks like so (open this in the applescript editor, select the file you want to run it on in the Finder, then run the script):
    tell application "Finder"
              set mainFolders to the selection
      -- selection returns as a list, so even if there's only one folder a loop is used
              repeat with thisFolder in mainFolders
      --get the folder's contents
                        set containedItems to every item of thisFolder
                        repeat with thisItem in containedItems
      -- get name of file, add 'ƒ' to avoid name conflicts
                                  set newFolderName to (displayed name of thisItem) & " ƒ"
      --make folder, move item
                                  set newFolder to make new folder at thisFolder with properties {name:newFolderName}
      move thisItem to newFolder
                        end repeat
              end repeat
    end tell

  • Computer shuts down when trying to create or open a pdf file

    My computer shuts down when trying to create or open a pdf file.

    In that case, you need to update the Acrobat Version at your end. Click on Help -> Check for Updates. Download and install the updates. Make sure your version is 9.5.1

  • Can't drag files into folders in PDF portfolio

    I have created a PDF portfolio that contains primarily PDFs converted from e-mail messages, along with a few files from various Microsoft Office products. The portfolio has been added to over time, and now we have almost 100 files in the portfolio, so we'd like to organize these files into folders so it is easier to use.
    However, when I create a folder, I am not able to drag any files into it. I've tried all different types of files--PDFs, Word, PowerPoint--when I drag the file on top of the folder, I get the circle backslash symbol indicating the function is not allowed. I can't find any information about this in the Help files; every tutorial I've looked at indicates that I should be able to drag and drop files wherever I like, but doesn't mention what to do if I can't.
    I'm using Acrobat Pro X on Windows XP with Service Pack 3.
    Any suggestions about why this might be happening and how to fix it would be greatly appreciated! I really don't want to have to recreate the whole thing, but it's not going to be very useful if we continue adding unorganized files.
    Thanks,
    Lisa

    I tried a different layout (I had a custom layout set up; I switched to the standard Grid), and I still can't drag and drop.
    I just now created a new portfolio with a few of the same files, and I was able to drag the files into a folder I created.
    Yes, the original portfolio was created in Acrobat 9.
    Thanks,
    Lisa

  • All of a sudden, I am unable to click-and-drag files into folders?

    I have a 2012 Macbook Air 11". I was dragging files into folders and then all of a sudden I couldn't. All I can do is copy and paste...frustrating.
    I tried accessibility settings, enabling dragging but that didn't change anything. Any suggestions?

    Restart your Mac and try again.

  • Drag and drop files into folders in iPad reader? or iTunes?

    is it possible to drag and drop files into folders in iPad reader? or iTunes?  It is very clunkey to have to click each separate file to instruct it to move to the folder.  Better still, can I just sync an existing folder on my hard drive so the pdf's inside always remain up to date on my iPad?

    There is no way to drag and drop in Reader on an iPad.
    There is no way to sync PDFs in a folder on your hard drive to those inside of Reader.
    There are readers (which are NOT free) which let you do some of these things and have more capabilities. You might check out PDF Expert from Readdle which costs $9.99 US.

  • How do i organise my files into folders in iCloud. If i can't this clearly isn't a replacement for MM and idisk

    Hey
    Does anyone know the deal with the documents in icloud. I used to have many different folders with documents in idisk. I need to seperate my files into folders. How can this replace i disk????

    I agree - my early days with iCloud are disappointing, particularly since it seems to (extraordinarily) have fewer mail rules than the Mac.
    For file sharing I have gone along a different route.  Have a look at http://www.evernote.com/  I share any information I might want to see or use on my iPad and iPhone when away from my Mac on Evernote - tax forms, essential documents, pdf files, recipes...  I have put them on the evernote 'cloud' (though you could choose to have copies on your devices) and can use Pages, Numbers, pdf readers etc.  Basically you can put pretty well anything into a 'note' and store your notes in 'notebooks'.
    I am as pleased with Evernote as I am not with iCloud. It is so sad, I have used Apple kit since 1985.  I still love it and wouldn't dream of buying a Windows machine, but I feel that the software development guys are losing touch with those of us who don't just want to surf the web and take photos.
    ps It took me a day or two to grasp the structural concepts of Evernote.  Well worth perservering.

  • Cannot move files into folders on desktop

    Hi, I cannot move files into folders on desktop.  They won't go in when I grab them and drag them to a folder.

    Take these steps if the cursor changes from an arrow to a white "prohibited" symbol when you try to move an icon on the Desktop.
    Sometimes the problem may be solved just by logging out or restarting the computer. Try that first, if you haven't already done it. Otherwise, continue.
    Select the icon of your home folder (a house) in the sidebar of a Finder window and open it. The Desktop folder is one of the subfolders. Select it and open the Info window. In the General section of the window, the Kind will be either Folder  or something else, such as Anything.
    If the Kind is Folder, uncheck the box marked Locked. Close the Info window and test.
    If the Kind is not Folder, make sure the Locked box is not checked and that you have Read & Write privileges in the  Sharing & Permissions section. Then close the Info window and do as follows.
    Back up all data before continuing.
    Triple-click anywhere in the line below on this page to select it:
    xattr -d com.apple.FinderInfo Desktop
    Copy the selected text to the Clipboard by pressing the key combination command-C.
    Launch the built-in Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad and start typing the name.
    Paste into the Terminal window by pressing command-V. You should get a new line ending in a dollar sign ($). Quit Terminal.
    Relaunch the Finder.
    If the problem is now resolved, and if you use iPhoto, continue.
    Quit iPhoto if it's running. Launch it while holding down the option key. It will prompt you to select a library. Choose the one you want to use (not the Desktop folder.)

  • Cannot put files into folders

    I cannot put files into folders after the update. The app crashes dramatically. Please fixed it otherwise it is useless.

    Hi,
    We are aware of the issue and are currently working on fixing the same.
    Thanks,
    Ankit
    Adobe Reader Team

  • I can not move my files into folders or trash

    I can not move my files into folders or trash,I continually have a message that says "working " on moving to a folder or trash,but it never gets done.
    I used to be able to drop and drag any files into any folders or into the trash.Please help.
    Thanks,
    iskaroll

    Please carefully read and use this article to help troubleshoot your Trash problem:
    http://www.thexlab.com/faqs/trash.html

  • Importing third party XML files into form-based publishing

    Hi,
    I want to import third party XML files into form-based publishing. My problem is that when I open the files, they are presented as normal XML files.
    The 'type' property is not set to "form-based publishing". That's the reason no form is linked to the XML file.
    Is there a way to change the value of this 'type' property? Then I can set it to "form-based publishing".
    Message was edited by: E. van der Palen

    Hi,
       You should take into account two things:
    1. XML Repository filter
    System Administration-System Configuration-KM-CM-Repository Filters-choose XML Forms Repository Filter
    edit it and add your repository.
    After that you have to restart it.
    2. Resource Type.
    You should modify cm_resourcetype property to set form-based publishing.
    You could edit this xml file using form builder and then set this parameter.
    Patricio.

  • OSX Server webdav bug? - files and folders disappears when filenames are fewer than 7 characters

    OSX Server webdav bug? - files and folders disappears when filenames are fewer than 7 characters
    Dear Community,
    i have a BIG problem with Apple webdav.
    All files or folders with fewer than 7 characters in filename disappear.
    The problems is only between Mac Server and Mac Clients
    and exists since OSX Server 1 (Server 10.7, 10.8, 10.9) on ALL Macs i know.
    The problem persist ever and occurs in the following settings:
    Mac Server (1.x, 2.x, 3.x) <> Mac Clients (10.7.x, 10.8.x, 10.9.x, 10.6 not tested)
    The problem does NOT occur in the following settings:
    Mac Server <> Windows Clients
    Mac Server <> Linux Clients
    Linux Server (my Webhoster) <> Mac Clients
    Windows Server (my Webhoster) <> Mac Clients
    So i think it is not a problem with server itselv or a single client only,
    it is probaly a problem with the combination betwen mac servers and mac clients.
    This is NOT a problem with MY MacServers/Clients only and not with only one Server.
    It occurs in many different Places and many different Machines.
    I have contact Apple Support more then tree times (always when i setup a new machine with server.app)
    but she said they heard first time about that and she cannot reproduce that problem.
    please, can somebody try it out?
    sorry for my bad englisch.
    best regards
    rené

    Supplement note:
    The Problem occurs also between OSX Server <> OpenWRT (Linux)
    best regards
    rené

  • How can I get iTUNES library to display renamed files and folders (renamed with Windows Explorer)?

    How can I get iTunes library to display the new names and organisation of tracks and albums (ie files and folders) that I have renamed and reorganised (using Windows Explorer) having previously imported them using iTunes?
    (Even when I relocate "lost" tracks in iTunes (using the drop down menu facility to view in Windows explorer), although iTunes will then play the track, and knows where to find it, it refuses to display the track with its correct (new) name, or show it the correct (new) album.  That means I have lots of things called "Untitled" and "Track 01" etc, all of which have actually been renamed, but iTunes does not seem to have the capability to recognise the changes and update its library listing.  Another example - a Tchaikovsky CD with 3 major works in 13 tracks insists on displaying in iTunes as 13 tracks in one album, despite the fact that I have reorganised the tracks into 3 albums - two being Swan Lake and The Nutcracker - and renamed the individual tracks to a more useable format.)

    Thanks for your replies ckuan
    I agree with Tgod that your first solution does not work.  It appears unpredictable whether the old or new file names are listed when you drag the folders into iTunes from Windows Explorer.  The folder structure is completely missing.  I reckon if you have to muck around spending days/weeks/months finding out how to fix links to a secret meta-file (obviously designed by some deep-cover microsoft worm working in the Apple!), then it's pretty obvious that almost any alternate way of doing this would be better.   Bye bye iTunes!!
    Incidentally, I tried several other things that (if the software was designed intuitively) should work, but give disastrous results:
    1) when deleting the library listing in iTunes, it gives you two options - one is to remove the listings to the Recycler.  Be aware that IF you select that option, it removes not only your library listing, but also your ACTUAL MUSIC FILES to the Recycler.  Moreover, it does NOT remove the insidious secret meta-file that is what apparently keeps rewriting old names over your carefully renamed file names, and keeps totally ignoring your carefully designed folder (album) structure.  OK - not a complete disaster, as I realised and went hunting through the chaos in the Recycler to recover all my files.  No thanks to the genius who designed this brilliant feature!
    2) after deleting the library listing in iTunes, I attempted to import just the folders that I wanted.  iTunes refused to allow me to do that, and proceeded to try to import every frigging music file it could find on my whole hard drive, in apparently random fashion into the library.  Whoever thought up that doozy either never ever tried to use or market test it, or has modified their mind rather too many times with artificial substances so their brain is like muesli chop suey.
    3) oh why go on, it's too depressing ...

  • Droplet to Rename and Move files into Folders

    Hello,
    I am a Graphic Designer and I am trying to optomize my workflow. I would like to be able to save out files with different prefixes in a folder then run a droplet on the folder that will create sub-folders and move the files to their respective folders based on their prefix. I would also like to remove the prefix from the filename after it is moved.
    Here is an example of what I am trying to achieve:
    So far I am able to Create the folders, and move the files, but I am stuck on removing the prefixes from the filename.
    property aFolder : "a"
    property bFolder : "b"
    property cFolder : "c"
    property dFolder : "d"
    property eFolder : "e"
    try
              tell application "Finder" to set theLocation to the selection as alias
              tell application "Finder" to set thePath to the selection as text
    on error
              tell application "Finder" to set theLocation to (folder of the front window as alias)
    end try
    tell application "Finder"
              if not (exists folder aFolder of theLocation) then
      make new folder at theLocation with properties {name:aFolder}
              end if
              if not (exists folder bFolder of theLocation) then
      make new folder at theLocation with properties {name:bFolder}
              end if
              if not (exists folder cFolder of theLocation) then
      make new folder at theLocation with properties {name:cFolder}
              end if
              if not (exists folder dFolder of theLocation) then
      make new folder at theLocation with properties {name:dFolder}
              end if
              if not (exists folder eFolder of theLocation) then
      make new folder at theLocation with properties {name:eFolder}
              end if
    end tell
    tell application "Finder"
              set this_list to every file of theLocation
              repeat with i in this_list
                        if (name of i) begins with "a" then
                                  move i to thePath & "a:"
                        else if (name of i) begins with "b" then
                                  move i to thePath & "b:"
                        else if (name of i) begins with "c" then
                                  move i to thePath & "c:"
                        else if (name of i) begins with "d" then
                                  move i to thePath & "d:"
                        else if (name of i) begins with "e" then
                                  move i to thePath & "e:"
                        end if
              end repeat
    end tell

    Here:
    property aFolder : "a"
    property bFolder : "b"
    property cFolder : "c"
    property dFolder : "d"
    property eFolder : "e"
    tell application "Finder"
    try
    set theLocation to the selection as alias
    on error
    set theLocation to (folder of the front window as alias)
    end try
    if not (exists folder aFolder of theLocation) then make new folder at theLocation with properties {name:aFolder}
    if not (exists folder bFolder of theLocation) then make new folder at theLocation with properties {name:bFolder}
    if not (exists folder cFolder of theLocation) then make new folder at theLocation with properties {name:cFolder}
    if not (exists folder dFolder of theLocation) then make new folder at theLocation with properties {name:dFolder} 
    if not (exists folder eFolder of theLocation) then make new folder at theLocation with properties {name:eFolder}
    set this_list to every file of theLocation
    repeat with i in this_list
    if (name of i) begins with "a" then
    move i to folder "a" of theLocation
    else if (name of i) begins with "b" then
    move i to folder "b" of theLocation
    else if (name of i) begins with "c" then
    move i to folder "c" of theLocation
    else if (name of i) begins with "d" then
    move i to folder "d" of theLocation
    else if (name of i) begins with "e" then
    move i to folder "e" of theLocation
    end if
    set name of (the result) to items 3 thru -1 of (get name of (the result)) as string
    end repeat
    end tell
    (98558)

Maybe you are looking for

  • IPod Nano Frozen please help :)

    Hello, My 3rd Gen. iPod Nano has frozen on me. This is what happened in detail..: I turned my ipod on and it just came on stuck on a screen which is a song that is playing . The ipod says that it is on hold but it isn't. The volume bar is showing con

  • User file usage on network shares

    I need to create a PowerShell script where I can show how much storage space users are using.  This would be for users on multiple network shares, above a certain amount (5 GB for example) and then exported to a CSV.  Is it possible to show the first

  • Tape based

    This is not necessarily a question but more of a comment. I do use Final Cut Pro 7 but am starting to use Final Cut Pro X and find I really like it. The only thing that is hard is that all my HD and SD cameras are tape based. Importing inFCP7 Is easy

  • Is Microsoft Project 2010 available for Mac?

    I have a class that is requiriing this software but only provides the windows free trial cd. Is this downloadable for Mac?

  • Data saving

    Hallo, i have problem in saving data i aquire from the DAQ. I programmed a VI ,with two simulated signals(i can replace them with DAQ VI) and added all the necessary VIs to get the data i want! when i want to save this data ,i wanted it with so many