Simple FAYT script that allows you to create a file or folder. This project is largely my attempt to port @Hurpin's indispensable Better "New Text Document" Script into FAYT
Creates a folder by default. Supports creating nested folders, and files of any type. E.g. including ".ext" creates a file of that type instead. If you wish to write contents to that file, insert a : (followed by the content).
The default activation key is //. After that you just enter the command in the filter bar that pops up. Requires version 13.19.2 to have // as the activation key. If you are on an earlier version, you can change the key in Preferences/Quick Keys.
14/11/25
I have found that '.' actually works better as the activation key.
Neat. I will check this out. Glad my better new text document thingy is helpful/inspiring. I feel like it should've been a standard feature 30 years ago. Lol
In preferences go to quick keys. You have to press an activation key, and then you just type it. I forget the default activation key, but i have mine bound to //.
Fixed. It was the result of changing the activation key from ? to //. I had tested it with the original ?. I have updated the original post with updated script. It also now sets // to the activation key by default.
// Original script idea from J.Fourie
// Creating Files and Folders from FAYT
// The default quick key is: "!".
// By default, a new folder will be created.
// Add another "!" to the beginning of the name to open the new folder.
// To create a file, add an extension.
// To add content to the file, add ":" after the extension.
// Eg: !New folder Create a folder "New folder"
// Eg: !!New folder Create a folder "New folder" and open it
// Eg: !New file.txt Create a file "New file.txt"
// Eg: !New file.txt:Blabla Create a file "New file.txt" with "Blabla" as its content
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "");
};
}
var fsu = DOpus.FSUtil();
function OnInit(initData) {
initData.name = "FAYT_NewFile";
initData.version = "1.0";
initData.copyright = "2025 Albator V (Thomas Michiels) - original idea J.Fourie";
initData.desc = "Quick folder creation by default, file if one dot. Supports :content.";
initData.min_version = "13";
initData.url = "https://resource.dopus.com/t/create-file-folder-fayt";
initData.default_enable = true;
initData.group = "FAYT";
}
function OnAddCommands(addCmdData) {
var cmd = addCmdData.AddCommand();
cmd.name = "New file";
cmd.method = "OnFAYT";
cmd.icon = "script";
cmd.hide = true;
var fayt = cmd.fayt;
fayt.enable = true;
fayt.key = "!"; // Touche rapide d'activation
fayt.realtime = true;
fayt.wantempty = true;
fayt.label = "New folder or file";
fayt.textcolor = "#ffffff"; // Blanc
fayt.backcolor = "#fc0fc0"; // Rose
}
function OnFAYT(data) {
if (data.key !== "return") return;
var tab = data.tab;
if (!tab) return;
var cmdline = String(data.cmdline || "").trim();
// Suppression des // si présent
if (cmdline.indexOf("//") === 0) {
cmdline = cmdline.slice(2);
}
cmdline = cmdline.trim();
if (!cmdline) return;
// Découpage du nom et contenu avec les ":"
var idx = cmdline.indexOf(":");
var rawName = (idx >= 0 ? cmdline.slice(0, idx) : cmdline).trim();
var content = (idx >= 0 ? cmdline.slice(idx + 1) : "").trim();
// Nettoyage de l'emplacement
rawName = rawName.replace(/[\\:\*\?<>\|]/g, "").replace(/\//g, "\\");
if (cmdline.slice(0, 1) === "!") {
rawName = rawName.slice(1);
}
if (!rawName) rawName = "NewFile";
var parts = rawName.split(".");
var isFile = (parts.length === 2); // one dot only
var baseDir = String(tab.path);
var target = uniqueName(baseDir, rawName, isFile);
if (isFile) {
// Création des dossiers parents si besoin
var parent = fsu.NewPath(target).Parent;
if (parent && parent.IsValid && !fsu.Exists(parent)) {
var cmd = DOpus.Create().Command();
cmd.ClearFiles();
cmd.AddLine('CreateFolder NAME="' + String(parent) + '"');
cmd.Run();
}
// Création de fichier
var fh = fsu.OpenFile(target, "w");
if (fh && fh.error === 0) {
if (content) fh.Write(content);
fh.Close();
DOpus.Output("[Created File] " + target);
} else {
DOpus.Output("[ERROR] Failed to create file: " + target);
}
} else {
// Création de dossier
var cmd2 = DOpus.Create().Command();
if (cmdline.slice(0, 1) === "!") {
cmd2.RunCommand('CreateFolder READAUTO NAME="' + target + '"');
} else {
cmd2.RunCommand('CreateFolder NAME="' + target + '"');
}
DOpus.Output("[Created Folder] " + target);
}
tab.CloseFAYT();
}
function uniqueName(basePath, relPath, isFile) {
var path = fsu.NewPath(basePath);
var name = relPath;
var base = name, ext = "";
var sep = name.lastIndexOf("\\");
var folder = (sep >= 0 ? name.slice(0, sep) : "");
name = (sep >= 0 ? name.slice(sep + 1) : name);
var dot = name.lastIndexOf(".");
if (isFile && dot > 0) {
base = name.slice(0, dot);
ext = name.slice(dot);
} else {
base = name;
}
var sub = fsu.NewPath(basePath);
if (folder) sub.Add(folder);
var full = sub + "\\" + base + ext;
for (var i = 2; fsu.Exists(full); i++) {
full = sub + "\\" + base + " (" + i + ")" + ext;
}
return full;
}