A poor mans Knapsack problem

I’m looking to split a directory into 2GB chunks.
I usually use automator and have a very very limited knowledge of AppleScript.
I’ve tried to use bash for this but its just making a mess of my home folder!
Anyway I found Knapfake2 by julifos http://macscripter.net/viewtopic.php?id=12871 which is amazing, but its actually too good for me!
I’m ideally looking at keeping the directory sorted by name, and not worried about space optimisation.
So if a file doesn’t fit in the folder a new one is made and it carries on filling that folder until a new one needs to be made.

I’m assuming its a far easier implementation than knapfake but I can’t work out what code is superfluous for my needs, or if its easier to just start again.

If anyone can point me the right direction that would be great.

The end use would be splitting a directory of Raw files to be uploaded in 2 GB chunks.

Thanks

Hi I’ve managed to cobble this together from various sources, but I think it can be improved upon as its very very slow.
Firstly I’d love for this to be a droplet and not have to choose the folder but I just can’t seem to get it to work that way from the input in automator.
Secondly if the files could just be moved to where they started that would be good and finally, I’d like the script to archive each new folder it makes.

This still seems like a lot of code for what seems like a very simple task!

I’ve found an free app that splits the folders called folder splitter but I wanted it to be super lightweight and to be fair the app hasn’t been updated in a while and is looking a bit dated!

on run {input, parameters}
	
	tell application "Finder"
		set files_folder to folder (choose folder with prompt "Choose the folder where items to be sub-divided are located currently")
		set destination_folder to folder (choose folder with prompt "Choose the folder where I should locate the items in different folders")
		
		set target_size to 2000.0 --   size limit your after in MB.
		
		set file_groupings to {} -- list we will store our stuff in
		set current_files to {} -- list of the current files we are adding size 
		
		set total_files to the count of files in files_folder
		
		set current_size_count to 0
		
		repeat with i from 1 to total_files
			set file_size to (the size of file i of files_folder) / 1024.0 / 1024.0 -- convert to MB to help prevent overrunning what the variable can hold
			
			if ((current_size_count + file_size) ≥ target_size) then
				-- this will overrun our size limit so store the current_files and reset the counters
				set the end of file_groupings to current_files
				set current_files to {}
				set current_size_count to 0
			end if
			
			set current_size_count to current_size_count + file_size
			set the end of current_files to (a reference to (file i of files_folder) as alias)
			
			if (i = total_files) then
				-- its the last file so add the current files disreagarding current size
				copy current_files to the end of file_groupings
			end if
			
		end repeat
		
		-- Copy the files into sub folders
		set total_groups to the count of file_groupings
		repeat with i from 1 to total_groups
			set current_group to item i of file_groupings
			set dest_folder to my ensureFolderExists(("disk " & i), destination_folder)
			move current_group to dest_folder
		end repeat
		
	end tell
	
end run
on ensureFolderExists(fold_name, host_folder)
	tell application "Finder"
		if not (exists folder fold_name of host_folder) then
			return make new folder at host_folder with properties {name:fold_name}
		else
			return folder fold_name of host_folder
		end if
	end tell
end ensureFolderExists