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

Delete files below 10 kb

New Here ,
Oct 17, 2018 Oct 17, 2018

Copy link to clipboard

Copied

Hi Adobe fans

how do i delete small images in a folder ?

var folder = Folder.current;

var files = folder.getFiles("*.png");

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

     if (files.size < 10000 ){

          alert(files.name +" deleted ")

          files.remove();

     }

}

TOPICS
Scripting

Views

494

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

Valorous Hero , Oct 17, 2018 Oct 17, 2018

The File.length property shows your the file size.

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 17, 2018 Oct 17, 2018

Copy link to clipboard

Copied

According to the OMV, it doesn't appear that file size is available to us.. I looked through all the available properties and methods and nothing points in that direction.. I also tried some 'common sense' options that aren't listed and none of those worked either.

Is there some specific reason that you want to do this task from illustrator? It sounds like a task better suited for a shell script.

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
New Here ,
Oct 17, 2018 Oct 17, 2018

Copy link to clipboard

Copied

My script is create images files from the layers "png files"

But when a layer is empty it create a small black square png image.

can I make a: if a layer is empty don't run the export function?

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 ,
Oct 17, 2018 Oct 17, 2018

Copy link to clipboard

Copied

So your script exports each layer as a PNG, then you want to retroactively go back and delete any PNGs that were exported from empty layers?

Can you share the script that you're using so i can try to make some suggestions? My inclination is that you should check to see if a layer is empty before exporting it, rather than exporting it and then deleting it later.

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
Valorous Hero ,
Oct 17, 2018 Oct 17, 2018

Copy link to clipboard

Copied

The File.length property shows your the file size.

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 ,
Oct 17, 2018 Oct 17, 2018

Copy link to clipboard

Copied

ah, yes. of course... because calling that property "size" or "fileSize" would have been confusing. instead, let's go with a name that's almost always used to denote an integer count of elements in an array.

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
New Here ,
Oct 17, 2018 Oct 17, 2018

Copy link to clipboard

Copied

var folder = Folder.current;

var options = new ExportOptionsPNG24();

options.horizontalScale = 400;

options.verticalScale = 400;

options.antiAliasing = false;

options.transparency = true;

var document = app.activeDocument;

if (document && folder)

parseLayer(document, "", 1);

function parseLayer(layer, base, depth) {

alert

var popups = [];

var takeShots = true;

log(depth, "parsing " + layer.name);

for (var i = 0; i < layer.layers.length; i++) {

var l = layer.layers;

var name = l.name;

var subLayer = true;

if (name.indexOf("(+)") != -1) {

l.visible = true;

subLayer = false;

log(depth + 1, name + " : always on");

}

else

if (name.indexOf("(-)") != -1) {

l.visible = false;

subLayer = false;

log(depth + 1, name + " : always off");

}

else

if (name.indexOf("(~)") != -1) {

l.visible = false;

subLayer = false;

popups.push(l);

}

else {

slides.push(l);

}

}

log(depth, "slides = " + slides);

// hide all popups

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

popups.visible = false;

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

var l = slides;

// show current slide, hide all the others

for (var j = 0; j < slides.length; j++) {

slides.visible = i == j;

log(depth, "setting " + slides.name + " visibility = " + (i == j));

}

parseLayer(l, base + (base == "" ? "" : "-") + l.name, depth + 1);

takeShots = false;

}

// hide all slides

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

slides.visible = false;

// capture popups

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

var l = popups;

l.visible = true;

var fname = base + "-" + l.name + ".png";

var file = new File(folder.fsName + "/" + fname);

log(depth, " capture <" + fname + ">");

document.exportFile(file, ExportType.PNG24, options);

l.visible = false;

}

if (takeShots) {

var fname = base + ".png";

var file = new File(folder.fsName + "/" + fname);

log(depth, " capture <" + fname + ">");

document.exportFile(file, ExportType.PNG24, options);

}

}

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
New Here ,
Oct 17, 2018 Oct 17, 2018

Copy link to clipboard

Copied

LATEST

Final

$.writeln("==================");

$.writeln("Begin... ");

var folder = Folder.current;

var options = new ExportOptionsPNG24();

options.horizontalScale = 400;

options.verticalScale = 400;

options.antiAliasing = false;

options.transparency = true;

var document = app.activeDocument;

if (document && folder)

parseLayer(document, "", 1);

function parseLayer(layer, base, depth) {

var slides = [];

var popups = [];

var takeShots = true;

log(depth, "parsing " + layer.name);

for (var i = 0; i < layer.layers.length; i++) {

var l = layer.layers;

var name = l.name;

var subLayer = true;

if (name.indexOf("(+)") != -1) {

l.visible = true;

subLayer = false;

log(depth + 1, name + " : always on");

}

else

if (name.indexOf("(-)") != -1) {

l.visible = false;

subLayer = false;

log(depth + 1, name + " : always off");

}

else

if (name.indexOf("(~)") != -1) {

l.visible = false;

subLayer = false;

popups.push(l);

}

else {

slides.push(l);

}

}

log(depth, "slides = " + slides);

// hide all popups

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

popups.visible = false;

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

var l = slides;

// show current slide, hide all the others

for (var j = 0; j < slides.length; j++) {

slides.visible = i == j;

log(depth, "setting " + slides.name + " visibility = " + (i == j));

}

parseLayer(l, base + (base == "" ? "" : "-") + l.name, depth + 1);

takeShots = false;

}

// hide all slides

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

slides.visible = false;

// capture popups

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

var l = popups;

l.visible = true;

var fname = base + "-" + l.name + ".png";

var file = new File(folder.fsName + "/" + fname);

log(depth, " capture <" + fname + ">");

document.exportFile(file, ExportType.PNG24, options);

l.visible = false;

}

if (takeShots) {

var fname = base + ".png";

var file = new File(folder.fsName + "/" + fname);

log(depth, " capture <" + fname + ">");

document.exportFile(file, ExportType.PNG24, options);

}

var files = folder.getFiles("*.png");

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

if (files.length < 2050) {

files.remove();

}

}

}

function log(depth, t) {

for (var j = 0; j < depth; j++)

$.write("----");

$.writeln(t);

}

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