get detailed file info
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
get detailed file info
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?
Re: get detailed file info
Hi shaosean,
As far i know you have to do your own
I use a simple lineoffset() to get informations about one file
Best regards
Jean-Marc
As far i know you have to do your own
I use a simple lineoffset() to get informations about one file
Best regards
Jean-Marc
https://alternatic.ch
Re: get detailed file info
ahh.. I didn't even think of the lineOffset, I've been using a loop.. Thanks for the tip 

-
- VIP Livecode Opensource Backer
- Posts: 10045
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: get detailed file info
Here's the function I use, which may save you some time with some of the tedious error-checking. Kinda handy, as it lets you get either one specified file attribute or an array with all of them:
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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn