Solution Use a JavaScript or a VB function.
Example
1
The following JavaScript function sets the file size, creation date,
"last modified" and "last accessed" date into GuiXT variables. It uses
the ISO format for date and time:
function get_file_info(filename) {
var fso = guixt.CreateObject("Scripting.FileSystemObject");
// file exists ?
if (!fso.FileExists(filename))
return
" ";
// file handle
var fh = fso.GetFile(filename);
// read file dates
var DateCreated =
new
Date(fh.DateCreated);
var DateLastModified =
new
Date(fh.DateLastModified);
var DateLastAccessed =
new
Date(fh.DateLastAccessed);
// set GuiXT variables with ISO date format
guixt.set("FileSize", fh.Size);
guixt.set("FileDateCreated", DateCreated.toISOString());
guixt.set("FileDateLastModified", DateLastModified.toISOString());
guixt.set("FileDateLastAccessed", DateLastAccessed.toISOString());
return
"X";
}
GuiXT script:
CallJS found
= get_file_info
"&V[myfilename]"
Example 2
If you prefer to get the date in the local time zone and in a different
format, for example YYYY-MM-DD hh:mm:ss, use the following functions:
function get_file_info(filename) {
var fso = guixt.CreateObject("Scripting.FileSystemObject");
// file exists ?
if (!fso.FileExists(filename))
return
" ";
// file handle
var fh = fso.GetFile(filename);
// read file dates
var DateCreated =
new
Date(fh.DateCreated);
var DateLastModified =
new
Date(fh.DateLastModified);
var DateLastAccessed =
new
Date(fh.DateLastAccessed);
// set GuiXT variables with ISO date format
guixt.set("FileSize", fh.Size);
guixt.set("FileDateCreated", date_out(DateCreated));
guixt.set("FileDateLastModified", date_out(DateLastModified));
guixt.set("FileDateLastAccessed", date_out(DateLastAccessed));
return
"X";
}
//
format date as YYYY-MM-DD hh:mm:ss
function date_out(dt)
{
var year = dt.getFullYear();
var month = dt.getMonth() + 1;
var date = dt.getDate();
var hours = dt.getHours();
var minutes = dt.getMinutes();
var seconds = dt.getSeconds();
if (month < 10) month =
'0' + month;
if (date < 10) date =
'0' + date;
if (hours < 10) hours =
'0' + hours;
if (minutes < 10) minutes =
'0' + minutes;
if (seconds < 10) seconds =
'0' + seconds;
return
(year +
"-" + month +
"-" + date +
" " + hours +
":" + minutes +
":" + seconds);
}
|