Javascript to remove certain contents of folder but copy subfolders as well

Post Reply
braam
Newbie
Posts: 7
Joined: Wed Aug 31, 2011 11:28 am

Javascript to remove certain contents of folder but copy subfolders as well

Post by braam » Wed Sep 28, 2011 9:44 am

Hi



I have a Switch Java script that I modified from other scripts that accepts a folder, look for a certain string in a file, and does not copy that file over with the rest of the files in the folder (I basically just want to delete this file from the folder, but as the filename always differs slightly, I had to create a script for this).....this works perfectly, however, none of my subfolders and their contents gets copied either. I am not sure how to do this (copy all subfolders as well), any suggestions or tips will be awesome. I am using Powerswitch 08, on Windows 7.



So just to explain what happens, folder goes into the script, outputs all files except files that contains "CRC_", but does not output any subfolders with their files.





Here is my current script:

function jobArrived( s : Switch, job : Job )

{

if (job.isFolder())

{

var jobDir = new Dir(job.getPath());

var files = jobDir.entryList("*", Dir.Files, Dir.Name);

var doc;

var tempFolder = job.createPathWithName(job.getName(), true);



for (var i = 0; i < files.length; i++)

{

var tempfile = "";

var file = new File(jobDir.path + "/" + files);



if (file.name.indexOf("CRC_") == -1)

s.copy(job.getPath() + "/" + file.name, tempFolder + "/" + file.name);

}



job.sendToSingle(tempFolder);

job.sendToNull(job.getPath());



}

else

job.sendToSingle(job.getPath());

}

Post Reply