Skip to main content
Participant
September 10, 2022
Question

Copy files once location has been found

  • September 10, 2022
  • 2 replies
  • 166 views

Hey yall! I'm trying to write a little script that will find all the assets in my AE script that are associated with a file, and then copy said files to a new location but I seem to have hit a roadblock on the copy portion. My code runs and I'm getting the printout of all the locations of the assets but it doesn't seem to be translating to the copy, is there something obvious I'm missing? I'm including the script here as well. Thanks so much!

 

var assetLocos = getAssetLocations();
var assetLocations = new Array();
var assetArray = new Array();
var copyToLoco = new Folder("~/Desktop/main");


function getAssetLocations()
{
var array = [];
var array2 = [];
for(var i = 1; i <= app.project.numItems; i++)
{
if(app.project.item(i).mainSource)
{
if(app.project.item(i).mainSource.file)
{
array.push(decodeURI(app.project.item(i).mainSource.file));
}
}
}


return array;
}

for (var i = 0; i<assetLocos.length; i++)
{
$.writeln(assetLocos[i]);
copyFolder(assetLocos[i], copyToLoco,)
}

function copyFolder(sourceFolder, destinationFolder)
{
var sourceChildrenArr = sourceFolder

var sourceChild = sourceFolder;
var destinationChildStr = destinationFolder.fsName + "/" + sourceChild.name;
if (sourceChild instanceof File)
{
copyFile(sourceChild, new File(destinationChildStr));
}
}

function copyFile(sourceFile, destinationFile)
{
if (!sourceFile.copy(destinationFile))
{
if (!data.supressAlerts)
{
alert('Unable to copy\n' + sourceFile + '\nto\n' + destinationFile + '\nAborting.');
errors = true;
return false;
}
};
}

This topic has been closed for replies.

2 replies

Mylenium
Legend
September 12, 2022

Without any system info and pertinent debug Info like the actual string output you see nobody can tell you much. Could be something like an extra delimiter being required or for that matter setting the base path manually in the script before appending the URI. That may in particular apply to external drives or mapped network drives with a specific folder structure. That and of course permissions issues and all that.

 

Mylenium 

Participant
September 12, 2022

That is true, I'm not getting anyt good debug info from Extendscript it just says it completes without error. I'm just trying to get the copy portion now with the paths being the desktop/main folder and the source being "~/Desktop/HDRI/001/Cafe_HDRI.jpg" the code completes in full but just nothing is actually copying

Mylenium
Legend
September 10, 2022

You have an extraneous comma on line 29 after your copyToLoco function call. That alone could throw off things. And your use of semicolons is inconsistent as well.

 

Mylenium

Participant
September 12, 2022

hmmm I see that there, but with those modifications I'm getting all the file locations but no file copying. Do I need to do anything special with the URI to have it be able to copy?