Page 1 of 1

open list file

Posted: 01 Jun 2018 09:42
by farshadmo368
hi,
I want to open 1,000 pdf files with app wps office + pdf .

open 1.pdf Action
2 seconds sleep
open 2.pdf The same action
2 seconds sleep
open 3.pdf The same action
.2 seconds sleep
.
.
.
.open 999.pdf the same action
2 seconds sleep
open 1000.pdf The same action

Their tuning is boring
Is there a good way?
please send answer or flow to my email or Here
farshadmo68@gmail.com

Re: open list file

Posted: 01 Jun 2018 13:10
by Desmanto
This is what you have asked in several other thread. I will just answer it here.

I don't use WPS office, but adobe reader. I think WPS should have the same viewer activity, so below method should work too.

You will need to
init the file list of the folder
Find out the pdf files only and convert it to URI format
Loop open the pdf files.

Action 1 : Init Variable File List
Variables : files
File pattern : /storage/emulated/0/Documents/* >> change this to your folder which contain the 1000 pdf files

Action 2 : Script
You will need to check the file ending and and add them to the list. Need to encodeURL and concatenate the file:///

Code: Select all

pdf = newList();
for(i in files)
{
  if(endsWith(i, "pdf"))
    addElement(pdf, "file:///" + replace(encodeURL(i), "%2F", "/"))
}
index = 0;
len = length(pdf);
The index is prepared for the loop. len is the maximum loop

Action 3 : Start Activity
Action : android.intent.action.VIEW
Data URI : {pdf[index]}
Explicit Component : Check
Package Name : com.adobe.reader
Class Name : com.adobe.reader.AdobeReader
Both the package name need to be changed to the WPS package name and the viewer class name. I can't help you with this one, try it by yourself until you get the correct class name.

i don't know what you mean by same action, so I just skip to sleep.
Action 4 : Sleep 5s (or how many you need)

Condition 1 :

Code: Select all

if(index < len-1)
{
  index = index + 1;
  return true;
}
else return false;
This will check if the index is bigger than the number of pdf files. If no, increment the index and loop again. If yes, then stop the flow.
True : goes back to Action 3 : Start Activity.
Loop pdf.png
Loop pdf.png (63.87 KiB) Viewed 16806 times

Re: open list file

Posted: 01 Jun 2018 15:02
by farshadmo368
i love you Desmanto
Let me test

Re: open list file

Posted: 01 Jun 2018 15:39
by farshadmo368
You very good
You are a computer god.
You're a peach.
Works.
Thankful

Re: open list file

Posted: 01 Jun 2018 15:45
by digitalstone
Yeah Desmanto... you're peachy haha :lol:

Re: open list file

Posted: 08 Jun 2018 21:37
by farshadmo368
Hi desmanto how are you?
I want to clear that file after a few seconds after opening any of the files, how?

Re: open list file

Posted: 09 Jun 2018 10:28
by Desmanto
Almost the same, but you have to add some new variable to store the delete list.

But first, do you really need to delete it every time after each opening? Or can you just wait until the whole 1000 loop finish and finally delete the 1000 files at the same time? I prefer the later if possible. Since you don't need to loop delete for 1000 times (takes much longer time), only need to delete 1 time, but 1000 files at once.

If you need to loop delete after each opening, just add a newList (delete) to accomodate the deletion. We don't use the same list (pdf), as delete Files action require a common path version, not the uri path version.

Code: Select all

pdf = newList();
delete = newList();
for(i in files)
{
  if(endsWith(i, "pdf"))
  {
    addElement(pdf, "file:///" + replace(encodeURL(i), "%2F", "/"));
    addElement(delete, i);
  }
}
index = 0;
len = length(pdf);
use {delete[index]} in the Delete Files action.

=========================
But if you can wait until the whole operation finish, then you can move the action Delete Files to the end after the loop (after the loop expression) and use {delete,listformat,comma} in the Delete Files action. This will delete 1000 files at once after all pdf opening is finished.

Be careful when dealing with Delete Files action. I suggest you test this first using notification on screen (or condition debug dialog), to show the delete path, check whether it is correct already. Make sure you also have make a copy of the test file, in case something wrong, you still have the backup.

Re: open list file

Posted: 09 Jun 2018 13:10
by farshadmo368
Thank you