Hi : I have a .js script to color according to file types, but it does not work, Someone can please help me. What is wrong?
Note: I want to color file types using a script.
I create a new button in Preferences/Customize toolbars and paste my code.
Here is the script :
// Import the Directory Opus API
import { DO_EVENT_AFTERFOLDERCHANGE, DO_EVENT_ONINIT } from "directoryopus-api";
// Initialization function
function OnInit() {
// Register event handlers
DO_RegisterEvent(DO_EVENT_AFTERFOLDERCHANGE, OnAfterFolderChange);
}
// Function to run when the folder changes
function OnAfterFolderChange() {
// Get the current folder
var currentFolder = DO_GetCurrentFolder();
// Get all files in the current folder
var files = DO_GetFilesFromFolder(currentFolder);
// Define a dictionary to map file extensions to colors
var colorMap = {
".exe": DO_RGB(255, 0, 0), // Red
".zip": DO_RGB(255, 0, 0), // Red
".rar": DO_RGB(255, 0, 0), // Red
".msi": DO_RGB(255, 0, 0), // Red
".iso": DO_RGB(255, 0, 0), // Red
".mobi": DO_RGB(128, 0, 128), // Purple
".epub": DO_RGB(128, 0, 128), // Purple
".pdf": DO_RGB(128, 0, 128), // Purple
".txt": DO_RGB(255, 255, 255), // White
".json": DO_RGB(255, 255, 255), // White
".ini": DO_RGB(255, 255, 255), // White
".csv": DO_RGB(255, 255, 255), // White
".docx": DO_RGB(0, 128, 255), // Cyan
".xlsx": DO_RGB(0, 128, 255), // Cyan
".pptx": DO_RGB(0, 128, 255), // Cyan
".mpp": DO_RGB(0, 128, 255), // Cyan
".accdb": DO_RGB(0, 128, 255), // Cyan
".mp3": DO_RGB(255, 128, 0), // Orange
".mp4": DO_RGB(255, 128, 0) // Orange
};
// Iterate through the selected files and apply colors based on their extensions
for (var i = 0; i < files.length; i++) {
var file = files[i];
var extension = file.Extension;
if (colorMap.hasOwnProperty(extension)) {
var color = colorMap[extension];
DO_SetFileColor(file, color);
}
}
}
// Register the OnInit function
DO_RegisterEvent(DO_EVENT_ONINIT, OnInit);