title: Sorting files into new folders based on first number using Applescript
body: <p>I'm trying to make a folder that will automatically create folders then sort the files into them based on the first number. The files I have to sort all come in a similar format with a name like,<strong><em>Feb 4 2.3 U#03 (3).mrd</em></strong>. My intention was to write some AppleScript to create a folder based on the number (2.3) then put all the files with (2.3) into that folder, and do the same with all the other files. </p>
  
  <p>I made a bit that sorts the files based on their number that seems to work,</p>
  
  <pre><code>set text item delimiters to {" "}
  tell application "Finder"
      set aList to every file in folder "Re-namer"
      repeat with i from 1 to number of items in aList
      set aFile to (item i of aList)
      try
        set fileName to name of aFile
        set firstPart to text item 1 of fileName
        set secondPart to text item 2 of fileName
        set thirdPart to text item 3 of fileName
        set fourthPart to text item 4 of fileName
        set fifthPart to text item 5 of fileName
        set newName to thirdPart &amp; " " &amp; secondPart &amp; " " &amp; firstPart &amp; " " &amp; fourthPart &amp; " " &amp; fifthPart
      set name of aFile to newName
      end try
  end repeat
  end tell
  </code></pre>
  
  <p>now I just need to create the new folders based on the first number and put the matching files in. I tried to make a script for this too (keep in mind I've never coded before and have no idea what I'm doing) and unsurprisingly it didn't work :(</p>
  
  <pre><code>tell application "Finder"
  open folder "Re-namer"
  set loc to folder "Re-namer"
  set aList to every file in loc
  repeat with i from 1 to number of items in aList
      set aFile to (item i of aList)
      if not (exists folder named "text item 1" in loc) then
          make new folder in loc with properties {name:"text item 1"}
      else
          move aFile in folder "text item 1"
      end if
  end repeat
  end tell
  </code></pre>
  
  <p>I've found a few similar questions but I still can't get it to work. If anyone has any ideas or resoures to help with this question I would greatly appreaate it. </p>