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

Copy Files to another location without Changing DateModified using Javascript

Contributor ,
Sep 05, 2012 Sep 05, 2012

Copy link to clipboard

Copied

Hi Expert,

         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. But If I did it with JS codes, It's showing today's date for all(created, modified,accessed). I want the same as the copied file.  I worked out this in Java. But I need to did this only by using Javascript. Can anyone help me.......

My codes is:

File("C:\\Users\\Indesign\\Desktop\\New folder (2)\\abc\\1.jsx").copy("C:\\Users\\Indesign\\Desktop\\New folder (2)\\xyz\\1.jsx")

Thanks and Regards,

Vel.

TOPICS
Scripting

Views

5.7K

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

Guru , Sep 18, 2012 Sep 18, 2012

I'm sorry for the late reply, couldn't get down to this earlier.

Here's an example:

Main();

function Main() {

    if (File.fs == "Windows")  {

        var file = new File("/E/Temp_1/Test.txt");

        var destinationFolderPath = "/D/Temp_2/";

        var destinationFolder = new Folder(destinationFolderPath);

        if (!destinationFolder.exists) destinationFolder.create();

        var vbScript = 'Set fs = CreateObject("Scripting.FileSystemObject")\r';

        vbScript +=  'fs.CopyFile "' + file.fsName.r

...

Votes

Translate

Translate
Guru ,
Sep 05, 2012 Sep 05, 2012

Copy link to clipboard

Copied

Hi Vel

See http://forums.adobe.com/message/4671706#4671706 for a  recent discusion on it.

You can't do it in JS but you can use doscript to call on AS and VB to do it.

Seems to have the answer.In particular look at Kasyan Servetsky's script.

Vel it's an idea to do a search before you ask the questions if you would of typed in "copy" the above post would of come up first.

Regards,

Trevor

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
Contributor ,
Sep 05, 2012 Sep 05, 2012

Copy link to clipboard

Copied

Hi Trevor,

      I thank you for your kind reply. But It's designed for Mac na... I'm using windows 7...

Thanks and Regards,

Vel.

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
Guru ,
Sep 05, 2012 Sep 05, 2012

Copy link to clipboard

Copied

It's design for both Mac and Windows

See my annotation (Kasyan's script).

function MoveFile(myFile, myFolder) {

    if (!myFile instanceof File || !myFolder instanceof Folder || !myFile.exists || !myFolder.exists) return false;

    var myMovedFile = new File(myFolder.absoluteURI + "/" + myFile.name);

//*************************************************************************************************************************************** 

// THIS IS THE WINDOWS BIT

//************************************

  if (File.fs == "Windows")  {

        var myVbScript = 'Set fs = CreateObject("Scripting.FileSystemObject")\r';

        myVbScript +=  'fs.MoveFile "' + myFile.fsName + '", "' + myFolder.fsName + '\\"';

        app.doScript(myVbScript, ScriptLanguage.visualBasic);

//***************************************************************************************************************************************

// NOW STARTS THE MAC BIT

    }

    else if (File.fs == "Macintosh") {

        if (myFolder.fsName.match("Desktop") != null) {

            var myMacFolder = myFolder.fsName.replace(/\//g, ":");

            var myMacFile = myFile.fsName.replace(/\//g, ":");

            var myAppleScript = 'tell application "Finder"\r';

            myAppleScript += 'set myFolder to a reference to folder (name of startup disk & "' + myMacFolder + '")\r';

            myAppleScript += 'set myFile to a reference to file (name of startup disk & "' + myMacFile + '")\r';

            myAppleScript += 'tell myFile\r';

            myAppleScript += 'move to myFolder\r';

            myAppleScript += 'end tell\r';

            myAppleScript += 'end tell\r';

        }

        else if (myFolder.fsName.match("Documents") != null) {

            var myMacFolder = myFolder.fsName.replace(/\//g, ":");

            var myMacFile = myFile.fsName.replace(/\//g, ":");

            var myAppleScript = 'tell application "Finder"\r';

            myAppleScript += 'set myFolder to a reference to folder (name of startup disk & "' + myMacFolder + '")\r';

            myAppleScript += 'set myFile to a reference to file (name of startup disk & "' + myMacFile + '")\r';

            myAppleScript += 'tell myFile\r';

            myAppleScript += 'move to myFolder\r';

            myAppleScript += 'end tell\r';

            myAppleScript += 'end tell\r';

        }

        else {

            var myMacFolder = myFolder.fullName.replace(/\//, "").replace(/\//g, ":");       

            var myMacFile = myFile.fullName.replace(/\//, "").replace(/\//g, ":");

            var myAppleScript = 'tell application "Finder"\r';

            myAppleScript += 'set myFolder to folder "' + myMacFolder + '"\r';

            myAppleScript += 'set myFile to document file "' + myMacFile + '"\r';

            myAppleScript += 'tell myFile\r';

            myAppleScript += 'move to myFolder\r';

            myAppleScript += 'end tell\r';

            myAppleScript += 'end tell\r';

        }

        app.doScript(myAppleScript, ScriptLanguage.applescriptLanguage);

    }

    if (myMovedFile.exists) {

        return true;

    }

    else {

        return false;

    }

}

Going out now so don't expect any quick reply

Trevor

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
Contributor ,
Sep 06, 2012 Sep 06, 2012

Copy link to clipboard

Copied

Thanks again for your kind reply...

I used the script and it shows an error whilr running.

It shows,

error.jpg

then I go through google for this error and go through the below link.

http://helpx.adobe.com/legacy/kb/javascript-doscript-commands-fail-initiate.html

It's for CS4 & I'm having CS5.

But I'm using CS5. I can't find the specified Data key 838F........... in registry. Can u guide me...

Thanks and Regards,

Vel.

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
Guru ,
Sep 06, 2012 Sep 06, 2012

Copy link to clipboard

Copied

Sorry Vel,

I don't have time to look into things now I suggest you ask Kasayan on the link I gave at the top.

Trevor

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
Enthusiast ,
Sep 06, 2012 Sep 06, 2012

Copy link to clipboard

Copied

Hi,

seems like the Bridge copies files without changing modification date.

#target Bridge

var thumbnail = new Thumbnail(File.openDialog());

var target = new Thumbnail(Folder.selectDialog());

thumbnail.copyTo(target)

Painfully, it has to be launched to use ... 😉

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
Contributor ,
Sep 06, 2012 Sep 06, 2012

Copy link to clipboard

Copied

Hi Mr. Hans,

       Really Great.... Thanks a lot for your kind help............ It works fine..............

Thanks again.

With Regards,

Vel.

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
Guru ,
Sep 18, 2012 Sep 18, 2012

Copy link to clipboard

Copied

I'm sorry for the late reply, couldn't get down to this earlier.

Here's an example:

Main();

function Main() {

    if (File.fs == "Windows")  {

        var file = new File("/E/Temp_1/Test.txt");

        var destinationFolderPath = "/D/Temp_2/";

        var destinationFolder = new Folder(destinationFolderPath);

        if (!destinationFolder.exists) destinationFolder.create();

        var vbScript = 'Set fs = CreateObject("Scripting.FileSystemObject")\r';

        vbScript +=  'fs.CopyFile "' + file.fsName.replace("\\", "\\\\") + '", "' + destinationFolder.fsName.replace("\\", "\\\\") + "\\" + file.name + '"';

        app.doScript(vbScript, ScriptLanguage.visualBasic);

    }

}

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
Contributor ,
Sep 18, 2012 Sep 18, 2012

Copy link to clipboard

Copied

Thanks Kasyan...

Thak u for ur kind reply.

It's working fine in CS5.5. But in CS5, If i run this, it shows error, "Unable to load Adobe Indesign CS5 Type Library (Version 1.0)".

The error color showed in the below line.

app.doScript(vbScript, ScriptLanguage.visualBasic);


With Regards,

Vel.

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
Guru ,
Sep 18, 2012 Sep 18, 2012

Copy link to clipboard

Copied

I just tested it in CS5, Windows 7 and it works for me without any errors.

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
Guru ,
Sep 18, 2012 Sep 18, 2012

Copy link to clipboard

Copied

LATEST

Hi Vel,

Try replacing

app.doScript(vbScript, ScriptLanguage.visualBasic)

with

app.doScript(vbScript, ScriptLanguage.UNKNOWN, undefined, UndoModes.ENTIRE_SCRIPT, "Kasyans Copy");

Shouldn't make a difference but worth giving a go.

Regards

Trevor

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