-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbatch_convert_to_binary.jsx
54 lines (42 loc) · 1.84 KB
/
batch_convert_to_binary.jsx
1
//~ batch export to bytesmain();function main(){ var allImages = loadFiles("*.png"); // opens a prompt and lets the user choose a folder if(allImages == null) return; // if that what the function returns null is - cancel var folder = allImages[0].parent; //~ alert(allImages); for(var i = 0; i < allImages.length;i++){ var curfile = File (allImages[i]); curfile.open ('r'); curfile.encoding = 'BINARY'; var str = curfile.read(); curfile.close(); var newfile = new File (folder.fsName + '/' + curfile.name + '.txt'); newfile.open('w'); newfile.encoding = 'UTF-8'; newfile.write(str.toSource()); newfile.close(); } // end loop i //~ for(var j = 0; j < imgstrings.length;j++){//~ var newfile = new File (folder.fsName + '/' + allImages[j].name + '.txt');//~ newfile.open('w');//~ newfile.encoding = 'UTF-8';//~ newfile.write(imgstrings[j]);//~ newfile.close();//~ //~ }return 0; } // end mainfunction loadFiles(type){ // the function that loads the filesvar theFolder = Folder.selectDialog ("Choose the Folder");// user select a folderif(!theFolder){ // if the folder is not a folder cancel the script return; // this cancels the whole function image_loadFiles }; // end folder checkvar allImages = theFolder.getFiles(type);// get the files by typeif((allImages.length < 1)||(allImages == null) ){// again if check if there are images alert("There are no images of the type: " + type);// hm something went wrong? User error return null; // so we cancel the function }else{ return allImages; // give back the images. Success! };// end all images check };// end function loadFiles