• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Suggest me! File modify date changing when copying

Engaged ,
Mar 31, 2016 Mar 31, 2016

Copy link to clipboard

Copied

Hi Everyone!,

I have to copy one file and paste into another location using java script. After the transition the file modified date was changed to current date and time.

However, If I copy file physically and paste into other location. The File modified date was not changed. This is what I exact want.

Anyone explain why its happen?

- yajiv

Code:

var myFile=File("/Volumes/tempFiles/1234.tif");

myFile.copy("~/Desktop/1234.tif");

Copy using Script:

Screen Shot 2016-03-31 at 4.57.51 pm.png

After Paste..

Screen Shot 2016-03-31 at 4.58.10 pm.png

TOPICS
Actions and scripting

Views

899

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 03, 2016 Apr 03, 2016

Both scripts are working fine...  However It's showing today's date for modified...

I can not reproduce that, the Created and Modified Dates are kept (see screen recording).

copyFileViaScript.gif

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 01, 2016 Apr 01, 2016

Copy link to clipboard

Copied

Sorry I can’t help you there, I see no way around this with JS.

Maybe VB or AS (depending on your OS) could provide a different result used in a ShellScript – but I am not sure it would or how to set it up …

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 01, 2016 Apr 01, 2016

Copy link to clipboard

Copied

Thanks for your reply Chris,

Can anyone help me.......

I've a issue while copying a file from one location to some other location. If I copied and paste manually, the Date modified is shown as same as copied file.

However If I did it with JS codes, It's showing today's date for modified. I want the same as the copied file by using Javascript.

-yajiv

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 01, 2016 Apr 01, 2016

Copy link to clipboard

Copied

You could use app.system() to issue an OS command.

On a PC it would be.

var file1 = new File("/path/to/file/file.name");

var dest = Folder ("/path/to/destination/folder");

var cmd = "copy " + file1.fsName + " " + dest.fsName;

app.system(cmd);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 02, 2016 Apr 02, 2016

Copy link to clipboard

Copied

Hi SuperMerlin,

Thanks for your response. The above mentioned command not working on MAC OS

I tried other scenario but can't work. However this command working in internal file transfer, not working server to desktop

Please suggest me, If any-other solution is there?

This command is working

var cmd="cp ~/Desktop/Test.tif ~/Documents"

Not Working..

var file1 = File("/Volumes/Test/Test.tif");

var dest = Folder (Folder.desktop);

var cmd = "cp " + file1.fsName + " " + dest.fsName;

app.system(cmd);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 02, 2016 Apr 02, 2016

Copy link to clipboard

Copied

You might have to use quotes around the paths:-

var cmd = "cp  \"" + file1.fsName + "\" \"" + dest.fsName +"\"";

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 02, 2016 Apr 02, 2016

Copy link to clipboard

Copied

Hi SuperMerlin and Chris,

Thank you so much for prompt response.

Both scripts are working fine...  However It's showing today's date for modified...

The File modified date was did not changed when I copy file physically and paste it into other location. 

Kindly suggest me or provide alternate solution.

-yajiv

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 02, 2016 Apr 02, 2016

Copy link to clipboard

Copied

The modified date should not change when using the OS command.

If all else fails you could use "touch" to set the modified and access to whatever you want.

touch(1) Mac OS X Manual Page

I don't have a mac so can't help with this.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 03, 2016 Apr 03, 2016

Copy link to clipboard

Copied

Both scripts are working fine...  However It's showing today's date for modified...

I can not reproduce that, the Created and Modified Dates are kept (see screen recording).

copyFileViaScript.gif

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 03, 2016 Apr 03, 2016

Copy link to clipboard

Copied

LATEST

Thanks you so much Chris, Michel and SuperMerlin,


Much Appreciated...   Both script are working awesome.

@Chris: I made mistake change "/" to ":", after correct the script work like a charm...

@SuperMerlin : Thank you so much for your kind support.

@Michel: Thank you so for leaning new things..


-yajiv

Love of Learning.. LOL

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2016 Apr 02, 2016

Copy link to clipboard

Copied

This works for me to copy a file from a folder named "bbb" to one named "aaa" one the volume "Pfaffi HD1".

#target photoshop

app.bringToFront();

var file = "Pfaffi HD1:bbb:HoughTransform.pdf";

var folder = "Pfaffi HD1:aaa";

var sh = app.system( 'osascript -e \'tell application \"Finder\"\ncopy file \"'+file+'\"to folder \"'+folder+'\"\nend tell\'' );

sh ? alert('Failed?') : alert('Done…');

Naturally you’d have to amend the paths of file and folder.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 03, 2016 Apr 03, 2016

Copy link to clipboard

Copied

This appears to work for me in Photoshop CS4 under Mac OS X Yosemite 10.10.5:

#target photoshop

app.bringToFront ();

var sourceFile = new File ("~/Desktop/source/test.txt");

var destFolder = new Folder ("~/Desktop/dest/");

if (!sourceFile.exists)

{

    alert ("Invalid source file!\r" + sourceFile.fsName);

}

else if (!destFolder.exists)

{

    alert ("Invalid destination folder!\r" + destFolder.fsName);

}

else

{

    var command = 'cp -p "' + sourceFile.fsName + '" "' + destFolder.fsName + '"';

    var sh = app.system (command);

    sh ? alert ('Failed?\r' + command) : alert ('Done…\r' + command);

}

It makes use of the system command cp with attribute -p.

Cf. man cp:

-p    Cause cp to preserve the following attributes of each source file in the copy: modification time, access time, file flags, file mode, user ID, and group ID, as allowed by permissions.  Access Control Lists (ACLs) and Extended Attributes (EAs), including resource forks, will also be preserved.

HTH,

--Michel

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines