Page 2 of 2

Re: Encrypt all files in the "Documents" folder

Posted: Tue May 03, 2022 12:24 pm
by Klaus
Why the unneccessary detour with -> the longfilepath?
From the dictionary:
...
Use the longFilePath function to get the long equivalent of a short file path passed from the command line.
...
"answer file..." is an LC command, nothing to do with the command line, and returns the long file path already.

Re: Encrypt all files in the "Documents" folder

Posted: Tue May 03, 2022 2:26 pm
by liveCode
I work with android and desktop this code I edited from mimu

Code: Select all

on mouseUp
   local XYZ,tencrypted
   answer file "Choose an RTF file to import"
   put it into FDA
   if the result = "cancel" then 
      exit mouseUp
   else
      put URL ("binfile:" & it) into XYZ
      encrypt XYZ using "aes-256-cbc" with password "richmond62" 
      put it into tencrypted
      if the result = "cancel" 
      then exit mouseUp
      else
         
         put tencrypted into URL ("binfile:"&FDA)
         get the longFilePath of FDA
         set the itemDelimiter to slash
         set the defaultFolder to item 1 to -2 of the longFilePath of FDA
      end if
   end if
end mouseUp
The code itself works but I want it to run this code on the document folder because that's where the user's result is stored

Re: Encrypt all files in the "Documents" folder

Posted: Tue May 03, 2022 2:41 pm
by Klaus
1.

Code: Select all

...
answer file "..."
...
will not work on mobile!

2.

Code: Select all

...
put URL ("binfile:" & it) into XYZ
encrypt XYZ using "aes-256-cbc" with password "richmond62" 
put it into tencrypted
if the result = "cancel" 
then exit mouseUp
else
...
The last "if the result = "cancel" does not make any sense at this place in the script!

3. You will need to set a marker, that all files have already been encrypted, or you will encrypt
already encrypted files and be surprised if you try to DEcrypt them later.

Conclusion:
You should encrypt "the user's result", which will probably be in a variable, BEFORE you write them to
a file in the users documents folder!

Re: Encrypt all files in the "Documents" folder

Posted: Tue May 03, 2022 5:17 pm
by jacque
If this is for Android, the user won't have easy access to the files in the document folder, they are sandboxed. Even a file manager can't see them, though a user who has rooted their phone could . So you may not need to encrypt them at all. It's rare these days for users to root their phones.

If you do want to encrypt anyway, use the files() function to get the list of files and encrypt each one inside a repeat loop.

Re: Encrypt all files in the "Documents" folder

Posted: Wed May 04, 2022 2:31 pm
by liveCode
Can you give me a code that encrypts these files?

Re: Encrypt all files in the "Documents" folder

Posted: Wed May 04, 2022 3:54 pm
by richmond62
Can you give me a code that encrypts these files?
That is exactly what has been explained in previous posts.

Re: Encrypt all files in the "Documents" folder

Posted: Wed May 04, 2022 3:57 pm
by liveCode
I succeeded