You are here: PSPad forum > English discussion forum > Re: Alt + D in file name

Re: Alt + D in file name

#1 Alt + D in file name

Posted by: Piotr | Date: 2022-03-15 09:01 | IP: IP Logged

Good morning,

is it possible to use the ALT + D (date in my custom text) shortcut in editing the name of a file / directory?

It makes a lot easier ...

Thanks for the great editor

Options: Reply | Quote | Up ^


#2 Re: Alt + D in file name

Posted by: vbr | Date: 2022-03-17 00:00 | IP: IP Logged

Piotr:
Good morning,

is it possible to use the ALT + D (date in my custom text) shortcut in editing the name of a file / directory?

It makes a lot easier ...

Thanks for the great editor

Hi,
I'm not sure, this functionality for inserting a timestamp can be use in filenames (maybe it is limited to the editor text and not available for filesystem operations (?))
However, it might be possible to achieve a similar functionality with PSPad Scripting.

You may try e.g. the following approach or tweak it to your needs. The scripting might need to be activated in program settings - system integration. The code below can be saved in a js. file in the Script directory; after that, call the menu Script: Recompile scripts.

The shortcut can be changed as well as the time format etc.

hth,
vbr

Quote:
/////// ... PSPad\Script\JScript\SaveFileTimestamp.js ////////
var module_name = "SaveFileTimestamp";
var module_ver = "1";

function save_file_name_with_timestamp(){
//save the active editor text with pre-filled timestamp in the filename
if (editorsCount()<1){return;}
var actEd = newEditor();
actEd.assignActiveEditor();
var fileNameStr = actEd.fileName();
var dt = new Date();
var str_dt = "__"+dt.getFullYear()+"_"+(dt.getMonth()+1)+"_"+dt.getDate()+"__"+dt.getHours()+"_"+dt.getMinutes()+"_"+dt.getSeconds()+"_";
str_dt = str_dt.replace(/_(\d)_/g, "_0$1_"); // pad single-digit items with zeros
str_dt = str_dt.replace(/_$/g, ""); // remove trailing _
if ((path_match = fileNameStr.match(/^(.*)\.([^.\r\n]*?)$/)) != null){
path_file_part = path_match[1];
path_ext_part = path_match[2];
fileNameStr = path_file_part + str_dt + "." + path_ext_part;
}

// save directly
// actEd.saveFileAs(fileNameStr);

// save as dialog with a pre-filled timestamp
actEd.fileName(fileNameStr);
runPSPadAction("aSaveAs");
}

function Init(){
addMenuItem("save filename - timestamp", "", "save_file_name_with_timestamp","Ctrl+Alt+Shift+W");
}

Options: Reply | Quote | Up ^






Editor PSPad - freeware editor, © 2001 - 2022 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR