Hi,
I have dabbled with applescript before but I haven’t gone into create directories or anything.
Basically the situation is I have a backup log of the windows PC’s on the network thats does through automator and then produces a .rtf with a predefined name of “full_backup_log”.
I have decided I would like to keep copies of these for reference (but also keep the most current one where it is) in the future and have them organised under year and month (and maybe week but I am not sure how to get the week of the current date).
I would like to have a script that checks if the current year and month folders exist if so place the file under the current month folder in the current year folder and have the file name changed to current day and month.
I run these back ups once at the end of the day using rysnc in automator shell script.
Is there a way to do this at all?
Thanks,
Bruce
So I had a look around and cam dup with:
set the_folder to "/Users/server/Desktop/backup_info/Backup log full"
set month_info to month of (current date) as text
set day_info to day of (current date) as text
set log_location1 to POSIX file (the_folder)
set log_location2 to POSIX file (the_folder & "/" & month_info)
set filePath to the_folder & "/" & month_info & "/"
tell application "Finder"
if exists folder filePath then
tell application "Finder"
make new folder at log_location2 with properties {name:day_info}
end tell
else
tell application "Finder"
make new folder at log_location1 with properties {name:month_info}
end tell
end if
end tell
but in the log it shows that the folder does not exist and then tried to create it but it can’t because it exists.
I am not sure how to check if the folder already exists, I have some old code that checks if a file exists which is:
set filePath to parentFolder & "labels" & ":" & labelPath & labelFile
tell application "Finder"
if exists file filePath then
tell application "Finder"
open file filePath
end tell
else
display dialog "The file '" & filePath & "' does not exist"
end if
end tell
so I replaced if exists file with if exists folder and it compiles and runs but it can’t find the folder and just skips to else and tries to create the folder.
Is there anything wrong?
Thanks,
Bruce
EDIT:
Realised they need to be POSIX paths and it works fine.