JSFiddle - React, Tailwind, and code Playground

by Shirly Manor

HTML

Select a file: <input type="file" name="myFile">

JavaScript

// check if psd and tif contain layers;

// use it at your own risk;

var theFiles = myFile.openDialog ("please select file", checkForTIForPSD, true);

if (theFiles) {
console.log("has file");

var theNonLayered = [];

var theLayered = [];

for (var m = 0; m < theFiles.length; m++) {

var theFile = theFiles[m];

var check = hasLayers(theFile);

if (check == true) {theLayered = theLayered.concat(theFile.name);

theFile.rename("layered_"+theFile.name);

/* theFile.copy("~/Desktop/test/borders/aaa/"+theFile.name);

theFile.remove()*/

}

else {theNonLayered = theNonLayered.concat(theFile.name)
console.log("no file")
}

};

createTxtFile (theLayered, "layered");

createTxtFile (theNonLayered, "unlayered")

};

////// verify layers //////

function hasLayers (file){

file.open("r");

file.encoding = 'BINARY';

filestring = file.read();

file.close();

var count = filestring.search("layer", "i");

filestring = "";

if (count != -1) {var doesHave = true}

else {var doesHave = false};

return doesHave

};

////// filter-function for file-formats //////

function checkForTIForPSD (theFile) {

if (theFile.name.slice(-4) == ".tif" || theFile.name.slice(-4) == ".psd" || theFile.constructor.name == "Folder") {return true}

else {return false}

};

////// function to write a preference-file storing the selected condition //////

function createTxtFile (theText, theName) {

var thePrefFile = new File("~/Desktop/"+theName+".txt");

thePrefFile.open("w");

thePrefFile.write(theText.join("\r"));

thePrefFile.close()

};