automatically create single folders for each day for a date range

Hi,

I need to create a mass of folders between a date range like this:

2011.06.01
2011.06.02

2011.06.30
2011.07.01

I need a script or action that will do this for me. Anyone ready to give me the solution?

For example I would love to give the script the start (2011.06.01) and end date (2011.07.01) and let it then create the folders for me.

Many thanks for any help!

Hi,

try this, the error handling is quite poor


set startDate to getDate("Start Date")
set endDate to getDate("End Date")
set destinationFolder to (choose folder)

repeat until startDate > endDate
	tell startDate to set {yr, mn, dy} to {year, its month as integer, day}
	set folderName to (yr as text) & "." & pad(mn) & "." & pad(dy)
	tell application "Finder" to make new folder at destinationFolder with properties {name:folderName}
	set startDate to startDate + 1 * days
end repeat

on getDate(prompt)
	repeat
		set {text returned:textReturned} to display dialog prompt default answer ""
		set {TID, text item delimiters} to {text item delimiters, "."}
		set textItems to (text items of textReturned)
		set text item delimiters to TID
		if (count textItems) = 3 then
			try
				set currentDate to (current date)
				tell currentDate to set {its hours, its minutes, its seconds} to {0, 0, 0}
				tell currentDate to set {year, month, day} to textItems
				return currentDate
			end try
		else
			display dialog "bad format" buttons {"Cancel", "Try again"} default button 1
		end if
	end repeat
end getDate

on pad(v)
	return text -2 thru -1 of ("00" & (v as text))
end pad


Hi, Stefan.

‘month’ is another date propery label which needs ‘its’ in front of it in this context. Also, when setting one date to another, the ‘day’ should be explicitly set below 29 first to avoid any possible overflow to another month.

try
	set currentDate to (current date)
	tell currentDate to set {day, time} to {1, 0}
	tell currentDate to set {year, its month, day} to textItems
	return currentDate
end try

You guys rock!

Many thanks for your help and script, that was exactly what I was looking for and it worked out really cool and helps me to save time!

Again many many thanks!

Cheers

Yogie