Wednesday, March 20, 2019

#1 2019-02-22 03:52:13 pm

Charlie Hartley
Member
Registered: 2007-04-11
Posts: 42

Changing File Modification Date

I have a simple script that duplicates all the files in one folder into another one.

Applescript:

tell application "Finder"
   set sfolder to folder "path-to-folder1"
   set tfolder to folder "path-to-folder2"
   duplicate files of sfolder to tfolder with replacing
end tell

What I would like for it to do is also change the date modified on the duplicated files in the second folder. Is this doable?

Thanks,
Charlie

Model: MacBook Pro
AppleScript: 2.11
Browser: Safari 605.1.15
Operating System: macOS 10.14


Filed under: change modify date

Offline

 

#2 2019-02-22 07:10:09 pm

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 53

Re: Changing File Modification Date

I assume the modification date you want to use is the current date. I also assume that the destination folder contains other files whose modification dates should not be changed. I've used actual folders below so that I could insure the script works.

Applescript:

set sfolder to "Macintosh HD:Users:bob:Working:"
set tfolder to "Macintosh HD:Users:bob:Documents:"

tell application "Finder"
   set sfiles to every file in folder sfolder
   repeat with aFile in sfiles
       set aFileName to name of aFile
       duplicate aFile to folder tfolder with replacing
       set modification date of file (tfolder & aFileName) to (current date)
   end repeat
end tell

Offline

 

#3 2019-02-22 08:48:43 pm

Charlie Hartley
Member
Registered: 2007-04-11
Posts: 42

Re: Changing File Modification Date

That works perfectly. Thank you!

Offline

 

#4 2019-02-23 05:06:13 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3367

Re: Changing File Modification Date

No need for a loop.

Applescript:

set p2d to path to desktop as text
set newModDate to (current date) -- or what you want

tell application "Finder"
   set sfolder to (p2d & "Source") as alias
   set tfolder to (p2d & "Dest") as alias
   duplicate files of sfolder to tfolder with replacing
   
   set modification date of every file of tfolder to newModDate
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 23 février 2019 12:05:33

Offline

 

#5 2019-02-23 07:42:41 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 53

Re: Changing File Modification Date

Yvan Koenig wrote:

No need for a loop.

Applescript:

set p2d to path to desktop as text
set newModDate to (current date) -- or what you want

tell application "Finder"
   set sfolder to (p2d & "Source") as alias
   set tfolder to (p2d & "Dest") as alias
   duplicate files of sfolder to tfolder with replacing
   
   set modification date of every file of tfolder to newModDate
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 23 février 2019 12:05:33



My script was based on two stated assumptions, one of which was:

"I also assume that the destination folder contains other files whose modification dates should not be changed."

That's why I used a repeat loop and wrote the script as I did. If the OP wants to change the modification date of every file in the destination folder, then Yvan's script is certainly the better suggestion.

Last edited by peavine (2019-02-23 09:24:15 am)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)