Moving Files with the Finder

Hi All -

I’m looking for a way to open a folder with 10,000 files in it, for example, and move those into folders containing 100 items each. Any suggestions?

Thanks!

Do you have a naming convention in mind for the folders? Do the files need to be in a specific folder based on name or other criteria, or do you just want to break them down into smaller groups? Where should the new folders be created?

Just looking to break down the files into smaller groups. It would be best if the folders were placed within the original folder.

For example, a folder called “stuff” has 10000 text files in it. Their names are all different, like “thislist.txt” or “thatlist.txt”. Nothing really in common. If I had any naming convention in mind, I’d probably want the end result to be “stuff:100:” through “stuff:200:”. So, a numerical order would neatly organize these folders in an alphanumeric finder window.

I had thought that if I could tell applescript to count to 100, and somehow append that integer to the filename, it might be easier then to move the files into a new subfolder.

What do you think?

Thanks!

Tell me if this is close to what you need. It needs some error checking and refinement but I think it’s close enough to provide a foundation for a suitable script.

set filesPerFolder to 100
set zeroPadCalc to (count characters of (filesPerFolder as text)) - 1
set zeroPad to ""
repeat zeroPadCalc times
	set zeroPad to zeroPad & "0"
end repeat
set breakMeDown to (choose folder with prompt "Choose the folder you wish to break down into groups of " & filesPerFolder)
set targFolders to {}

tell application "Finder" to ¬
	set fileCount to count files of folder breakMeDown

if fileCount is greater than or equal to filesPerFolder then
	set newFolCount to fileCount / filesPerFolder
else
	set newFolCount to 1
end if

set newFolCount to round newFolCount rounding up
set inc to 0

tell application "Finder"
	activate
	open breakMeDown
	set root_ to name of breakMeDown
	repeat newFolCount times
		set inc to inc + 1
		
		if inc is equal to 1 then
			if fileCount is less than or equal to filesPerFolder then
				copy (make new folder at breakMeDown with properties {name:root_ & " - " & zeroPad & "1" & " thru " & fileCount}) to end of targFolders
			else
				copy (make new folder at breakMeDown with properties {name:root_ & " - " & zeroPad & "1" & " thru " & (filesPerFolder * inc)}) to end of targFolders
			end if
		else
			if inc is equal to newFolCount then
				copy (make new folder at breakMeDown with properties {name:root_ & " - " & ((filesPerFolder * inc) - (filesPerFolder - 1)) & " thru " & fileCount}) to end of targFolders
			else
				if inc is not equal to newFolCount and inc is not equal to 1 then
					copy (make new folder at breakMeDown with properties {name:root_ & " - " & ((filesPerFolder * inc) - (filesPerFolder - 1)) & " thru " & (filesPerFolder * inc)}) to end of targFolders
				end if
			end if
		end if
	end repeat
	
	repeat with folder_ in targFolders
		set count_ to count files of folder breakMeDown
		if count_ is greater than or equal to filesPerFolder then
			move files 1 thru filesPerFolder of breakMeDown to folder_
		else
			move files of breakMeDown to folder_
		end if
	end repeat
end tell

– Rob