You are here: PSPad forum > České diskuzní fórum > Re: Prevádzanie skriptu nad súborom .JS a .PHP pri ukladaní?
Posted by: AD7 | Date: 2026-08-04 19:50 | IP: IP Logged
Po čase sa vraciam k tejto funkcionalite.
Ako na to? Potrebujem v uvedených súboroch aktualizovať verzie podľa aktuálneho dátumu. 
Díky.
Posted by: AD7 | Date: 2026-08-05 18:45 | IP: IP Logged
1. riešenie:
'*************************************************************************************
' Update "Last update" date in current document and save it
'
' Example:
' // Last update: Jul 15, 2026
' becomes:
' // Last update: Aug 5, 2026
'
' Description : Updates the "Last update:" line to current date
' and saves the active document.
' Version : 1.0
'*************************************************************************************
Option Explicit
Const module_name = "UpdateLastDate"
Const module_ver = "1.0"
Sub UpdateLastDate
Dim editor
Dim txt
Dim re
Dim today
Dim newDate
Dim monthNames
Set editor = NewEditor()
editor.assignActiveEditor()
' Current date
today = Date
monthNames = Array( _
"Jan", "Feb", "Mar", "Apr", "May", "Jun", _
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" _
)
newDate = monthNames(Month(today) - 1) _
& " " & Day(today) _
& ", " & Year(today)
' Get complete document
txt = editor.Text
' Find:
' // Last update: Jul 15, 2026
'
' Everything after "Last update:" on that line is replaced.
Set re = New RegExp
re.Pattern = "(//[ \t]*Last update:[ \t]*)[A-Za-z]{3}[ \t]+[0-9]{1,2},[ \t]+[0-9]{4}"
re.Global = False
re.IgnoreCase = True
If re.Test(txt) Then
txt = re.Replace(txt, "$1" & newDate)
' Replace document contents
editor.command("ecSelectAll")
editor.selText(txt)
' Save active document
runPSPadAction("aSave")
Else
MsgBox _
"Line '// Last update: ...' was not found.", _
vbExclamation, _
"Update Last Date"
End If
Set re = Nothing
Set editor = Nothing
End Sub
' Name "Init" is required.
' It is called automatically by PSPad during script initialization.
Sub Init
addMenuItem _
"Update Last Date && Save", _
"Date / Version", _
"UpdateLastDate", _
"Shift+Ctrl+S"
End Sub
Posted by: AD7 | Date: 2026-08-05 18:45 | IP: IP Logged
2. riešenie:
'*******************************************************************************
' PSPad - Update Last Update date and Save
'
' Description : Updates "// Last update: Mon D, YYYY" in active document
' with current date and saves the document.
' Supports : PHP, JavaScript and any text file containing the marker.
' Shortcut : Ctrl+Shift+S
'*******************************************************************************
Option Explicit
Const module_name = "UpdateVersion"
Const module_ver = "1.00"
'*******************************************************************************
' Main procedure
'*******************************************************************************
Sub UpdateVersion
Dim obj
Dim txt
Dim newDate
Dim re
Dim matches
Set obj = NewEditor()
obj.assignActiveEditor()
' Get whole document
txt = obj.Text
' Format current date as e.g. Aug 5, 2026
newDate = EnglishDate(Date)
' Regular expression for:
'
' // Last update: Jul 15, 2026
'
' The rest of the document is untouched.
Set re = New RegExp
re.Pattern = "(//[ ]*Last[ ]+update:[ ]*)[A-Za-z]{3}[ ]+[0-9]{1,2},[ ]+[0-9]{4}"
re.Global = False
re.IgnoreCase = True
Set matches = re.Execute(txt)
If matches.Count = 0 Then
MsgBox "Marker '// Last update:' was not found.", _
vbExclamation, _
"Update version"
Exit Sub
End If
' Replace only the date
txt = re.Replace(txt, "$1" & newDate)
' Replace whole editor contents
obj.command("ecSelectAll")
obj.selText(txt)
' Save active document
runPSPadAction("aSave")
End Sub
'*******************************************************************************
' Return date using English abbreviated month names
'
' Example:
' Aug 5, 2026
'*******************************************************************************
Function EnglishDate(d)
Dim months
months = Array( _
"Jan", _
"Feb", _
"Mar", _
"Apr", _
"May", _
"Jun", _
"Jul", _
"Aug", _
"Sep", _
"Oct", _
"Nov", _
"Dec" _
)
EnglishDate = months(Month(d) - 1) & _
" " & _
Day(d) & _
", " & _
Year(d)
End Function
'*******************************************************************************
' PSPad initialization
'*******************************************************************************
Sub Init
addMenuItem _
"Update Last update && Save", _
"Version", _
"UpdateVersion", _
"Shift+Ctrl+S"
End Sub
Posted by: AD7 | Date: 2026-08-05 18:47 | IP: IP Logged
v súbore sa hľadá riadok:
// Last update: Aug 5, 2026
a tu sa aktualizuje dátum + súbor sa uloží
s kláv. skratkou: Ctrl+Shift+S
Editor PSPad - freeware editor, © 2001 - 2026 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR