Choose folder of files, create folders based on filename mod help

Hi,

Every day I have a bunch of files in the format below:
1007117pm.mp4 – Stands for Oct 7th 2011 7pm
1007116pm.mp4
1007115pm.mp4
0817111pm.mp4 – Stands for Aug 17th 2011 11pm
0816111pm.mp4
08161111am.mp4
08161110am.mp4

The script below will:

  1. User chooses folder of files
  2. Goes thru list of files in the folder & creates a folder based on the filename
  3. Moves associated file into it’s new folder

My problem is that I need the script to create only one folder for all files that
are named for the same date.

So using the filenames listed above:
(there would only be one folder for the following dates)
100711 – so all mp4 files for that day go in here
081711 – so all mp4 files for that day go in here
081611 – so all mp4 files for that day go in here

– here is the script / Any help in the right direction is appreciated
Thanks for taking a look.


set chosen_folder to (choose folder)
tell (a reference to my text item delimiters) to set {old_delim, contents} to {contents, "."}
tell application "Finder"
try
set file_list to files of chosen_folder
on error
set file_list to {}
end try
repeat with this_file in file_list
set folder_name to name of this_file
if folder_name contains "." then set folder_name to ((text items 1 thru -2 of folder_name) as string)
set new_folder to ((chosen_folder as string) & folder_name & ":")
try
get new_folder as alias
on error
make new folder at chosen_folder with properties {name:folder_name}
end try
move this_file to folder new_folder
end repeat
end tell
set my text item delimiters to old_delim

Hi,

try this


set chosenFolder to (choose folder)
tell application "Finder" to set fileList to files of chosenFolder

repeat with aFile in fileList
	set {name:Nm, name extension:Ex} to info for (aFile as alias)
	if Ex is missing value then set Ex to ""
	if Ex is not "" then set Nm to text 1 thru ((count Nm) - (count Ex) - 1) of Nm
	set dateFolder to text 1 thru 6 of Nm
	set sourceFile to quoted form of POSIX path of (aFile as text)
	set destinationFile to quoted form of (POSIX path of chosenFolder & dateFolder & "/" & name of aFile)
	do shell script "ditto " & sourceFile & space & destinationFile
	do shell script "rm " & sourceFile
end repeat


Hi Stefan,

Thank you. Works perfect for me.
Will save me alot of time this year.

Jeff