get detailed file info
Posted: Sun Feb 12, 2017 12:25 pm
Is there a function to get the details of a single file, based on the file path, or do we need to find the file in the output from detailed files?
Questions and answers about the LiveCode platform.
https://forums.livecode.com/
Code: Select all
function fwFileInfo pFile, pAttribute
-- Returns file attributes for the file specified in pFile.
-- If pAttribute is empty, returns an array of all 11 elements
-- LiveCode's "detailed files" supports: Name,Size,ResSize,
-- CreationDate,ModifiedDate,AccessDate,BackupDate,UserOwner,
-- GroupOwner,Permissions,CreatorCode.
-- If any of those key names are passed as pAttribute, only
-- the value corresponding to that attribute is returned.
---------------------------------------------------------
-- File exists?
if there is not a file pFile then
return "No such file: "& \
quote& pFile "e for error
end if
--
put pFile into tPath
set the itemdel to "/"
delete last item of tPath
put the defaultfolder into tSaveDefaultFolder
set the defaultFolder to tPath
-- Can't set folder (permissions)?
if the result is not empty then
return "Couldn't access folder: "& \
quote& tPath "e& \
" ("& sysError()& ")" for error
end if
put the detailed files into tFiles
set the defaultfolder to tSaveDefaultFolder
--
put last item of pFile into tFileName
put lineoffset(cr& urlEncode(tFileName) &comma, cr& tFiles) into tLineNum
put line tLineNum of tFiles into tFileAttributes
--
put "Name,Size,ResSize,CreationDate,ModifiedDate,AccessDate,BackupDate," & \
"UserOwner,GroupOwner,Permissions,CreatorCode" into tAttribNames
set the itemdel to comma
if pAttribute is "Name" then
return urlDecode(item 1 of tFileAttributes)
else if pAttribute is not empty then
-- Return single attribute:
return item (itemoffset(pAttribute, tAttribNames)) of tFileAttributes
else
-- Return array of attributes:
put 0 into i
put empty into tAttribsA
repeat for each item tAttrib in tAttribNames
add 1 to i
put item i of tFileAttributes into tAttribsA[tAttrib]
end repeat
-- Normalize name form:
put urlDecode( tAttribsA["Name"]) into tAttribsA["Name"]
--
return tAttribsA
end if
end fwFileInfo