Skip to main content
M.Hasanin
Inspiring
August 19, 2022
Answered

Convert Selected Graphics Folder to Binary Encoded Files - Ready Made Script

  • August 19, 2022
  • 1 reply
  • 400 views

Hi All , this is not a question, its a script i want to share with you, its contribution script that maybe it will be useful for someone who need it, i need to convert many images to binary and only found scripts one by one to encode one image per time, so i wrote a script that will automatically convert all images to binary encoded text files, here it is :

 

//Convert Selected Graphics Folder to Binary Encoded  Files
//Written By : Mohammad Hasanin (M.Hasanin) in 19/8/2022

//Ask User Where is the Files
var selectedFolder = Folder.selectDialog("Select a folder for Encoding Graphics Files");

//Supporting Multiple Format 
var GrphFiles = selectedFolder.getFiles(/\.(?:png|gif|jpg|jpeg|bmp|tif|psd)$/i);

for(var i=0;i<GrphFiles.length;i++)
    {
            //Collect Files, Files Names
            var myFilesName = GrphFiles[i].name;
            var myFiles = GrphFiles[i];
           
            //One Hit to Save new File with Same Name of Original Replacing the Extension with (*.txt)
            var myEncodedGrphFiles = new File(selectedFolder.fullName + "/"+myFilesName.replace (/\.(png|gif|jpg|jpeg|bmp|tif|psd)$/,'')+".txt");

            //Open and Encode
            myFiles.open ("r");
            myFiles.encoding = "binary";
            var temp = myFiles.read();
            myFiles.close();

            //Write Encoded Graphic Files
            myEncodedGrphFiles.open("w");
            myEncodedGrphFiles.write(temp.toSource ());    
            myEncodedGrphFiles.close();   
}

 

and for all the expert engineers that i learned from you,  thanks a lot and im still learning! , and will be happy to see many ways to skin the cat!, any suggestion or additional point of view to enhance?

This topic has been closed for replies.
Correct answer m1b

Hi @M.Hasanin, thanks so much for sharing your script. 🙂

- Mark

1 reply

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
August 21, 2022

Hi @M.Hasanin, thanks so much for sharing your script. 🙂

- Mark

M.Hasanin
M.HasaninAuthor
Inspiring
August 22, 2022

@m1b you are very welcome 🙂

Mohammad Hasanin