What the heck? Writing and reading ios files??

William Prothero waprothero at gmail.com
Thu Jun 25 12:38:21 EDT 2020


Jacqueline:
Thanks for responding. I am really stuck on this. 

I can write the file, and get a list of the files I write, but when I try to read the file using the same code to create the filepaths, etc, the read routine says the file doesn’t exist. It all works in the dev environment. I had used a “_” char in the filenames, so I removed it. The read routine can’t find the file. Very wierd.

I’m going to try to make a very simple test case that I can run on my phone and post it, but I’m going to take a break. I’ve posted my file reading and writing code here, but there is probably too much to go through. 

Thanks for responding,
Bill


--saves an arbitrary array to the waterdetective local storage folder
--fname is the name of the db, tNameExt -"_Wkng" for added files, or "_Dwnld" for downloaded files.
on saveArrayToLocal fName,tArray
   put fixUpFName(fName) into fName
   if fname contains "meterReadingsA" then
      --breakpoint
   end if
   if the last char of fName is cr then
      delete the last char of fName
   end if
   put getPathToUserDocuments() into tFloc
   put tFloc into tFolder
   --put tFloc&"/"&"waterdetective" into tFolder
   checkCreateFolder tFolder
   put tFolder&"/"&fName into tDataFile
   delete file tDataFile
   put arrayEncode(tArray) into temp
   put base64encode(temp) into tData
   put tData into URL ("binfile:"&tDataFile)
   --put tData into URL ("file:"&tDataFile)
   wait 2 seconds
   --This is for testing with debug
   if there is a file tDataFile then
      put "Yes" into x
      put tDataFile into theLocalPath
   else
      put "No" into x
   end if
end saveArrayToLocal


on deleteLocalTempFiles tFileNameAddon
   put checkCreateLocalFolder() into tFolderPath
   put getTheLocalFiles() into tFiles
   repeat for each line tFile in tFiles
      put tFile&tFileNameAddon into theFileToDelete
      if not (char 1 of theFileToDelete is ".") then
         put tFolderPath&"/"&theFileToDelete into xFilePath
         delete file xFilePath
      end if
   end repeat
end deleteLocalTempFiles

function getTheLocalFiles
   put checkCreateLocalFolder() into tFolderPath
   set the defaultFolder to tFolderPath
   put files(tFolderPath) into tFiles
   return tFiles
end getTheLocalFiles

function isThereALocalFile fName
   put fixUpFName(fName) into fName
   put getPathToUserDocuments() into tFloc
   put tFloc&"/"&fName into tDataFile
   if there is a file tDataFile then
      return TRUE
   else
      return FALSE
   end if
end isThereALocalFile

function fixUpFName fName
   replace "_" with "xx" in fName
   return fName
end fixUpFName


--creates local folder and returns the folderPath
function checkCreateLocalFolder tFolder
   put getPathToUserDocuments() into tFloc
   if tFolder = "" then
      return tFloc
      exit checkCreateLocalFolder
   end if
   put tFloc&"/"&tFolder into tFolderPath
   checkCreateFolder tFolderPath
   return tFolderPath
end checkCreateLocalFolder

--retrieves an arbitrary array from the waterdetective local storage folder
function getArrayFromLocal fName
   put fixUpFName(fName) into fName
   if fname contains "meterReadingsA" then
      --breakpoint
   end if
   put getPathToUserDocuments() into tFloc
   put tFloc&"/"&fName into tFile
   put isThereALocalFile(fName) into isAFile
   if isAFile is TRUE then
      put URL ("binfile:"&tFile) into temp
      --put URL ("file:"&tFile) into temp
      put base64decode(temp) into temp
      put arrayDecode(temp) into tArray
   else
      return "Can't find file."
   end if
   return tArray
end getArrayFromLocal

on deleteLocalFile fName
   put fixUpFName(fName) into fName
   put getPathToUserDocuments() into tFloc
   put tFloc&"/"&"waterdetective/"&fName into tFile
   if there is a file tFile then
      delete file tFile
   end if
end deleteLocalFile

--tFolder is the complete path to the folder to be tested
on checkCreateFolder tFolder
   if there is not a folder tFolder then
      create folder tFolder
   end if
end checkCreateFolder

function getPathToUserDocuments tFolder
   put specialFolderPath("documents") into tPath
   if the environment contains "development" then
      put tPath&"/waterdetective" into tPath
   end if
   if tFolder = "" then
      return tPath
   else
      put tPath&"/"&tFolder into tPath
   end if
   return tPath
end getPathToUserDocuments

William A. Prothero
https://earthlearningsolutions.org

> On Jun 24, 2020, at 9:22 PM, J. Landman Gay via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
> Mobile is case-sensitive, desktop isn't. The "documents" folder should be all lower case.
> 
> If that's not the problem then show us the lines of script that both create the file path and retrieve it.
> 
> --
> Jacqueline Landman Gay | jacque at hyperactivesw.com
> HyperActive Software | http://www.hyperactivesw.com
> On June 24, 2020 10:06:45 PM prothero--- via use-livecode <use-livecode at lists.runrev.com> wrote:
> 
>> Added info:
>> I’ve tried putting the files in “cache”, in the “Documents” folder directly, and using
>>> put URL ("file:"&tFile)
>> to store the data. Didn’t change anything.
>> I also looked at the lesson on reading and writing livecode files. Nothing helps.
>> 
>> I’m using Livecode Business 9.6.0 on a Mac running 10.15.5
>> 
>> This is the last hurdle I have before am finished with this project. Any suggestions would be mucho appreciated.
>> 
>> Best,
>> Bill
>> 
>> William A. Prothero
>> Santa Barbara, CA. 93105
>> http://earthlearningsolutions.org/
>> 
>>> On Jun 24, 2020, at 5:35 PM, prothero--- via use-livecode <use-livecode at lists.runrev.com> wrote:
>>> 
>>> Folks:
>>> I’m having a very weird problem writing then reading the same file on ios. I must be missing something very basic. I’ve checked the path to the file when it is written and it matches exactly to the path when I try to read it. In the read routine, I check for the file’s existence and it says it doesn’t. But when I write the file and immediately check for the file’s existence (in the same handler), it says it exists. I’ve checked the path with the debugger and the path it writes to is exactly the same as the path it looks for the file in.
>>> 
>>> I must be missing something very basic. It works on my dev system, but in the phone, it can’t find the files it just wrote. Is there some kind of permission needed? I’m stumped.
>>> 
>>> Please enlighten me. There must be some really, really basic thing I’m missing.
>>> 
>>> Thanks,
>>> Bill
>>> 
>>> --retrieves an arbitrary array from the waterdetective local storage folder
>>> 
>>> function getArrayFromLocal fName
>>> 
>>> put getPathToUserDocuments() into tFloc
>>> 
>>> put tFloc&"/"&"waterdetective/"&fName into tFile
>>> 
>>> if the last char of tFile is cr then
>>> 
>>> delete the last char of tFile
>>> 
>>> end if
>>> 
>>> —It can’t find the file I just wrote
>>> if there is a file tFile then
>>> 
>>> put URL ("binfile:"&tFile) into temp
>>> 
>>> put base64decode(temp) into temp
>>> 
>>> put arrayDecode(temp) into tArray
>>> 
>>> else
>>> 
>>> return ""
>>> 
>>> end if
>>> 
>>> return tArray
>>> 
>>> end getArrayFromLocal
>>> 
>>> 
>>> function getPathToUserDocuments
>>> 
>>> put specialFolderPath("Documents") into tPath
>>> 
>>> return tPath
>>> 
>>> end getPathToUserDocuments
>>> 
>>> on saveArrayToLocal fName,tArray
>>> 
>>> if fname contains "meterReadingsA" then
>>> 
>>> breakpoint
>>> 
>>> end if
>>> 
>>> --put tNameExt after fName
>>> 
>>> if the last char of fName is cr then
>>> 
>>> delete the last char of fName
>>> 
>>> end if
>>> 
>>> put getPathToUserDocuments() into tFloc
>>> 
>>> put tFloc&"/"&"waterdetective" into tFolder
>>> 
>>> checkCreateFolder tFolder
>>> 
>>> put tFolder&"/"&fName into tDataFile
>>> 
>>> delete file tDataFile
>>> 
>>> put arrayEncode(tArray) into temp
>>> 
>>> put base64encode(temp) into tData
>>> 
>>> put tData into URL ("binfile:"&tDataFile)
>>> 
>>> wait 2 seconds
>>> 
>>> if there is a file tDataFile then
>>> 
>>> put "Yes" into x   —on ios I get “Yes"
>>> 
>>> put tDataFile into theLocalPath
>>> 
>>> else
>>> 
>>> put "No" into x
>>> 
>>> end if
>>> 
>>> end saveArrayToLocal
>>> 
>>> William A. Prothero
>>> Santa Barbara, CA. 93105
>>> http://earthlearningsolutions.org/
>>> 
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> 
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list