mikzik
09-14-2007, 05:43 AM
-- read attribute from dummy file
attrib = File.GetAttributes(_SourceDrive.."\\pagefile.txt");
-- read and create ISO format of AccessDate
strAccessDate = attrib.AccessDateISO;
-- display AccessDate in format 2007-09-14T11:34:54
Dialog.Message("", strAccessDate);
This work fine, but if I change pagefile.txt to pagefile.sys which is hidden and system file
I get error mesage:
Error
On Next, Line 9: attempt to index global `attrib'(a nil vaule)
For some reason it cant read attributes from hidden files!
Any Hint?:o
jassing
09-14-2007, 10:19 AM
This is a "known" issue.
I use FSO to get around this -- here's my "fso" file -- it has some functions that are "swapable" with the stock ones (takes the same paraeters, and returns the same data) It needs my BitWise Plugin (http://www.indigorose.com/forums/showthread.php?p=95810#post95810)
-- SUF's LUA objects (file.) don't handle hidden/system files very well
-- this wraps those items with fso objects.
function FSOFileThere( cFile )
local bFileThere = false;
--dbgout("Testing for file",cFile);
if not Empty( cFile ) then
local oFSO = luacom.CreateObject("scripting.filesystemobject");
if oFSO then
local cDrive = JustDrive( cFile );
if not Empty(cDrive) then
--dbgout("Getting status for drive",cDrive);
local oDrv = oFSO:GetDrive( cDrive ) ;
if oDrv then
if oDrv.IsReady then
bFileThere = oFSO:FileExists(cFile) ;
end
else
bFileThere = File.DoesExist( cFile );
end
end
oDrv = nil;
oFSO = nil;
collectgarbage();
else
bFileThere = File.DoesExist( cFile );
end
end -- empty()
return bFileThere;
end
function FSOFileVersion( cFile )
local cVersion = "";
if File.IsThere(cFile) then
local oFSO = luacom.CreateObject("scripting.filesystemobject");
if oFSO then
cVersion = oFSO:GetFileVersion(cFile) ;
oFSO = nil;
collectgarbage();
else
cVersion = File.VersionInfo( cFile );
end
end
return cVersion;
end
function FSOFileSize( cFile )
local nSize = -1;
if File.IsThere( cFile ) then
local oFSO = luacom.CreateObject("scripting.filesystemobject");
if oFSO then
local oFile = oFSO:GetFile(cFile) ;
assert(oFile,"File Object failed");
nSize = oFile.Size;
oFile = nil;
oFSO = nil;
collectgarbage();
else
nSize = File.Size( cFile );
end
end
return nSize;
end
function FileCRC( cFile )
end
function FSOFileInfo( cFile )
local tInfo = nil;
if File.IsThere( cFile ) then
local oFSO = luacom.CreateObject("scripting.filesystemobject");
if oFSO then
tInfo = {}; --WriteDateISO="", CreationDateISO="", AccessDateISO="",Type="",Normal=false,ReadOnly=false,System=false,Archive= false,Hidden=false,Temporary=false,Compressed=fals e};
local oFile = oFSO:GetFile( cFile );
assert(oFile,"File Object failed");
tInfo.WriteDateISO = ISODate(oFile.DateLastModified);
tInfo.CreationDateISO = ISODate(oFile.DateCreated);
tInfo.AccessDateISO = ISODate(oFile.DateLastAccessed);
local nAttr = oFile.Attributes;
if nAttr == 0 then
tInfo.Normal = true;
else
tInfo.ReadOnly = BitWise.BitAnd( nAttr, 1 )>0;
tInfo.Hidden = BitWise.BitAnd( nAttr, 2 )>0;
tInfo.System = BitWise.BitAnd( nAttr, 4 )>0;
tInfo.Archived = BitWise.BitAnd( nAttr, 32 )>0;
tInfo.Compressed= BitWise.BitAnd( nAttr, 2048 )>0;
end
tInfo.Type = oFile.Type;
oFile=nil;
oFSO=nil;
collectgarbage();
else
tInfo = File.GetAttributes( cFile );
tInfo.WriteDateISO = String.Transform(tInfo.WriteDateISO,"T"," ");
tInfo.CreationDateISO = String.Transform(tInfo.CreationDateISO,"T"," ");
tInfo.AccessDateISO = String.Transform(tInfo.AccessDateISO,"T"," ");
end
end
return tInfo;
end
function ISODate( cDate )
local cReturn = "";
-- Convert: 8/6/2000 1:50:20 AM MM/DD/YYYY HH:MM:SS A/PM
-- into: 2000-08-06 01:50:20 YYYY-MM-DD HH:MM:SS
if type(cDate) == "string" then
local cMonth = PadL(String.Left( cDate, String.Find( cDate, '/')-1), 2, '0');
cDate = String.Mid( cDate, String.Find( cDate, '/')+1, String.Length( cDate ) );
local cDay = PadL( String.Left( cDate, String.Find( cDate, '/')-1), 2, '0');
cDate = String.Mid( cDate, String.Find( cDate, '/')+1, String.Length( cDate ) );
local cYear = String.Left( cDate, 4 );
cDate = String.Mid( cDate, 6, String.Length( cDate ) );
-- Now cDate holds only the time.
local nHour = String.ToNumber( String.Left( cDate, String.Find(cDate,":")-1));
if String.Right(cDate, 2)=="PM" then
nHour = nHour + 12;
end
cDate = String.Left(cDate, String.Length(cDate)-3); -- get rid of AM/PM
cDate = String.Mid( cDate, String.Find(cDate,":"), String.Length(cDate) );
cReturn = cYear..'-'..cMonth..'-'..cDay..' '..PadL(nHour,2,'0')..cDate;
end
return cReturn;
end
-- Extend File object
File.IsThere = FSOFileThere;
File.Version = FSOFileVersion;
File.Size = FSOFileSize;
File.Info = FSOFileInfo;
mikzik
09-15-2007, 02:17 AM
wow, I will need time to analise this
Thanks:yes
jassing
09-15-2007, 10:08 AM
wow, I will need time to analise this
Thanks:yes
Get the bitwise plugin & put that code into a lua file and add it into your project.
then use File.Info() just like you'd use File.GetAttributes()
Powered by vBulletin™ Version 4.0.6 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.