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

Copy files from one folder to another

Engaged ,
Mar 12, 2011 Mar 12, 2011

I'm using CS4.

As part of my workflow, I output proofs as jpgs from the RAW files then upload them to a website. I run the "Export to jpg" script in Bridge with the option to run a script on completion. The script I'm trying to get working is supposed to copy those jpg files to another folder on my hard drive. I am having problems getting this to copy the files, though. After the "for" line I have tried everything I can think of but cannot seem to make file objects from the array elements contained in jpgs. I thought the array elements  were file objects so I tried jpgs

.copy(dst); but it doesn't copy anything. I then tried constructing a new File object from jpgs

.fsName and then using that to try to copy (var proofs=new File(jpgs

.fsName); proofs.copy(dst);).

Everything else works fine and the array jpgs is filled with the files in the referenced folder. If I set up an alert to show the iteration it steps through the file names properly. Can anyone tell me what I'm missing here?

#target "bridge"

var fst= app.document.presentationPath;
var o=new Folder(fst + "/Originals");
var dst=new Folder(fst.replace("Photography","Photoshoots"));
if (!dst.exists) if(confirm(dst.name + " does not exist. Create folder?")) dst.create();

if (dst.exists) {


    var jpgs=o.getFiles("*.jpg");
    for (var p in jpgs) {
        jpgs

.copy(dst);
    }
}

TOPICS
Scripting
2.2K
Translate
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

Guide , Mar 13, 2011 Mar 13, 2011

Paul, is correct when using Bridge you need to use 'thumbnails' of files and folder objects. There are numerous ways in which you can go about getting these from open document windows, collections, stacks etc… Here is a very straight forward example that just takes your file and folder objects creates a new thumbnail of each in order to work…

#target bridge var sFile = File('~/Desktop/Untitled-1.indd'); var dFold = Folder('~/Desktop/ID JUNK'); var res = copyTo(sFile,dFold); alert('File: '+dec

...
Translate
Engaged ,
Mar 12, 2011 Mar 12, 2011

I just tried this...

proof=jpgs

;

And when I check the value of proof in ETK, it shows a File object with the name of the last file in the referenced folder. However, while I'm typing in "proof.copy(dst)" I'll normally get a listing when I type the . that gives me my options. "Copy" is not among the options available even though this is a File object. Either way, the proof.copy(dst) function returns false but I get no errors.

Translate
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
Valorous Hero ,
Mar 12, 2011 Mar 12, 2011

Here is an example of copying files to a new folder....


var toDoFolder = new Folder(app.document.presentationPath+ '/Processing');
if(!toDoFolder.exists)  toDoFolder.create();
var sels = app.document.getSelection("jpg");
for(var a in sels){
  sels.copyTo(toDoFolder);
}

Translate
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 ,
Mar 12, 2011 Mar 12, 2011

What does "getSelection" return? I can't find a reference to it in the Bridge scripting guide. Does it require

files to be selected? Or a folder? Neither condition exists when I run this script.

I can't find "copyTo" either. I get an error "copyTo is not a function" when I try it.

Translate
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 ,
Mar 12, 2011 Mar 12, 2011

OK. I just changed it to jpgs

.execute(); and it opens up all jpg files in the default viewer for jpgs. But when I change it to copy(dst) it won't copy the files. The variable dst is set to the right folder because it does create it if it isn't already created. It just won't copy files into that folder.

Translate
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 ,
Mar 12, 2011 Mar 12, 2011

I got it to work by doing this.....

if (dst.exists) {
    var jpgs=o.getFiles("*.jpg");
    for (var p in jpgs) {
        jpgs

.copy(dst.fsName+"/"+jpgs

.name);
    }
}

Apparently just passing a folder name to the copy function isn't enough. The destination path/filename need to be passed.

Translate
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
Valorous Hero ,
Mar 13, 2011 Mar 13, 2011

var sels = app.document.getSelection("jpg"); will select all jpgs from the selected files or if no files are selected it will select all of them.

sels.copyTo(toDoFolder); this requires a thumbnail not a file.

If you download the Bridge SDK you will find all the documentation.


Translate
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 ,
Mar 13, 2011 Mar 13, 2011

Paul, is correct when using Bridge you need to use 'thumbnails' of files and folder objects. There are numerous ways in which you can go about getting these from open document windows, collections, stacks etc… Here is a very straight forward example that just takes your file and folder objects creates a new thumbnail of each in order to work…

#target bridge var sFile = File('~/Desktop/Untitled-1.indd'); var dFold = Folder('~/Desktop/ID JUNK'); var res = copyTo(sFile,dFold); alert('File: '+decodeURI(sFile.name)+' was copied to '+decodeURI(dFold.name)+' ' +res); // Will copy a file to another location function copyTo(source,dest) {           var sThum = new Thumbnail(source);      var dThum = new Thumbnail(dest);           var res = sThum.copyTo(dThum);           return res;      }; // Will move a file to another location on the // same mount point… Else its the same as copyTo() function moveTo(source,dest) {           var sThum = new Thumbnail(source);      var dThum = new Thumbnail(dest);           var res = sThum.moveTo(dThum);           return res;      };

Translate
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 ,
Mar 13, 2011 Mar 13, 2011

Thanks Paul and Mark. Is copying within Bridge better/faster by using the Thumbnails method vs just using file objects?

Translate
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
Valorous Hero ,
Mar 13, 2011 Mar 13, 2011

I don't know if it's any faster but I find it easier. As Mark has pointed out Bridge has the function to move a file, this is much better.

Translate
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 ,
Mar 13, 2011 Mar 13, 2011

Bridge's copyTo() does NOT bump the File's time stamp like the ESTK's File object copy command does… which I think is wrong…

Translate
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 ,
Mar 18, 2011 Mar 18, 2011

OK. The script itself is working fine now. I was having an issue when running it from the "Export to jpg" script so I did try it using the Thumbnails method you both recommended. I still got the same error. When I run the script by itself, it runs fine. When I run it from the Export script using the option to run a script once export is finished I get the error: "Reference error: error is undefined" Sometimes it does copy the files over but I still get the error. Here is what I have...

#target bridge

var fst= app.document.presentationPath;
var o=new Folder(fst + "/Originals");
var dst=new Folder(fst.replace("Photography","Photoshoots"));
if (!dst.exists) if(confirm(dst.name + " does not exist. Create folder?")) dst.create();

if (dst.exists) {
    var dThumb=new Thumbnail(dst);
    var jpgs=o.getFiles("*.jpg");
    for (var p in jpgs) {
        var sThumb=new Thumbnail(jpgs

);
        sThumb.copyTo(dThumb);
    }
}

The only thing I can figure is it has something to do with the Export script. Any ideas? Do you think it could be because Bridge hasn't had time to create all the thumbnails and previews before the script is trying to execute?

Translate
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 ,
Mar 18, 2011 Mar 18, 2011
LATEST

OK. I did some more digging around and it seems that when writing a script to use from the Export To JPEG script, it has to be in a certain format. Also, whenever you make a change to it and wish the change to take effect when running Export To JPEG, you must restart Bridge as the Export To JPEG script loads your script on startup just like any other startup script. The following does work.....

var ToPhotoshoots = {};
ToPhotoshoots.process = function(exportsArray) {
    var fst= app.document.presentationPath;
    //var o=new Folder(fst + "/Originals");
    var dst=new Folder(fst.replace("Photography","Photoshoots"));
    if (!dst.exists) if(confirm(dst.name + " does not exist. Create folder?")) dst.create();

    if (dst.exists) {
        var dThumb=new Thumbnail(dst);
        for (var p in exportsArray) {
            var sThumb=new Thumbnail(exportsArray

.exportPath);
            sThumb.copyTo(dThumb);
        }
    }
}
ToPhotoshoots;

Translate
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