Date modification script

Hello,

I’d like to create an application with applescript that compares the modification date and the creation date of 2 files of same name but different extensions placed in the same folder.
The application will:
1 - ask to choose a folder
2 - look in folders and subfolders for files with same name
3 - change the creation date of files whose extension is “abc” with the creation date of files whose extension is “bcd” and with same name

I hope i made myself clear to explain my purpose

Thanks for your help

Francois

Hi François,

welcome to MacScripter.

There is one problem: You can’t change the creation date of a file

And the modification date?

Hi Stefan,
is it not possible to change the creation date like this?

set file_path to POSIX path of (choose file)
do shell script "/Developer/Tools/SetFile -d 09/24/1973 " & file_path -- the date has to be in that format

I know Developer tools needs to be installed but it seems to do the trick. Adam Bell wrote the code in this post http://bbs.applescript.net/viewtopic.php?id=15393
Thanks,
Nik

Hi François,
if you have Developer Tools installed on your mac then can you give this script a try and see if it does what you want?

set source_folder to choose folder

tell application "Finder" to set pdf_list to every item of entire contents of source_folder whose name ends with ".pdf"

tell application "Finder" to set eps_list to every item of entire contents of source_folder whose name ends with ".eps"

repeat with this_pdf in pdf_list
	set pdf_creation_date to creation date of (info for (this_pdf as alias)) as string
	set pdf_name to the name of this_pdf
	set pdf_without_ext to characters 1 thru -5 of pdf_name as string
	repeat with this_eps in eps_list
		set eps_name to the name of this_eps
		set eps_without_ext to characters 1 thru -5 of eps_name as string
		if eps_without_ext contains pdf_without_ext then
			display dialog pdf_without_ext & " has a match!!!!"
			set creation_date to date pdf_creation_date
			set short_date to (short date string of creation_date)
			
			set myoffset to offset of "/" in short_date
			set theday to characters 1 thru myoffset in short_date as string
			set themonth to characters (myoffset + 1) thru (myoffset + 3) in short_date as string
			set theyear to "20" & characters (myoffset + 4) thru end in short_date as string
			
			set new_date to themonth & theday & theyear as string
			
			set eps_posix_path to quoted form of POSIX path of (this_eps as alias)
			do shell script "/Developer/Tools/SetFile -d " & new_date & " " & eps_posix_path
		end if
	end repeat
end repeat

for the purpose of this script I’ve worked with eps and pdf extension but you can change these to whatever you require.
Thanks,
Nik

fpedeboscq, what version of Mac OS X do you have?

10.4.11

In fact i have been thinking of an other program.

I have a JVC Everio camera with hard disk.
The files on the camera are some mpeg’s files but with a mod extension.
If i want it recognize by imovie08
1- i need to copy mod file rename with mpeg extension on my external hard drive in /Mp_Root/101PNV01 (a way to make hd recognised by imovie as an hd camera)
2 - i also d like to move and rename the copied files in /Mp_Root/101PNV01/"Year/Month/Day/“fileproject_time.mpeg”

If i copy the mod file from camera to usb hardrive i won t have problem with date of creation.

As improvement, i’d like it to start when i plug my camera and to check for files that are already copied on the usb hardrive.

I m new in programmation with applescript but i think it s a good exercice to learn it

Thanks for your help

Hi François,
I also have this Camera and have the same problem with the .MOD files. I’m not too sure what you’re trying to do exactly so can I suggest what I think is the best solution?

  1. select the folder containing .MOD files on the camera and get the name of all of these files without the extension (.MOD)

  2. select a folder to copy and rename the .MOD files too and get the name of all of these files without the extension (.mpg)

  3. If the folder that you want to copy too contains a file with the same name (excluding extension) then don’t copy the file, but if it doesn’t contain a file with the same name (excluding extension) then copy the file and change the .MOD extension to .mpeg

Thanks,
Nik

Good idea,

Thanks

I ll try to do it

Francois

Hi guys,
It’s a bit late in the conversation, but you can use the touch command to change file modification and creation times (at least on my PPC 10.4.11). Using
touch -t 7001131313 file
sets the modification and creation times of file to January 13, 1970 at 1:13 PM. Likewise, using
touch -r file1 file2
copies the times on file2 to the ones on file1.