two foreach sections do not want funktion one after another

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
zakhar
Posts: 179
Joined: 08 Sep 2010 21:13

two foreach sections do not want funktion one after another

Post by zakhar »

Hi all!

The following script
in the first part
1. checks if a folder contents a desktop.ini file,
2. if a dektop.ini file is not there, then а per $pathtothefiletoadd predefined desktop.ini file is copied,
3. script makes a record of that action,
in the second part
4. checks if a folder has the "system" attribute set,
5. if not, then the system attribute will be set,
6. script makes a record of that action.

The normal start situation is that the folders to be found have neither desktop.ini file nor the "system" attribute set.
Both script parts are located in the same script file.
XY 15.80 is running.

The problem is that the second part does not function properly if the first part was running right before
and the record made by the second part is strange too - it shows an incorrect action of the second part :( ,
it means, that the written lines of the second part record should handle the same folders in the same sequence as that of the first part - and this is not so...

So, to set the "system" attribute to the found files I must quote the first part and then execute the script one more time.

The usually bad result of this script is that far not all folders receive their system attribute set.

Code: Select all

 // first part of the script follows

 $folderindextosearch = "...";
 $pathtothefiletoadd = "...\desktop.ini";


 foreach ($a,quicksearch("$folderindextosearch /d","...",<crlf>),<crlf>) {
 $b = exists("$a\desktop.ini");
 if ($b == 0){
 copyto "$a","$pathtothefiletoadd",,1;
 writefile("...","<crlf>on $folderindextosearch desktop.ini copied on <date yyyy.mm.dd hh.nn.ss> from $pathtothefiletoadd     to     $a <*>",a,t);
 }
 }

// second part of the script follows
 foreach ($a,quicksearch("$folderindextosearch /d","...",<crlf>),<crlf>) {
 $b = exists("$a\desktop.ini");
 $c = attrstamp("s",0,"$a");
 if ($b == 1 && $c != "s") {
 attrstamp("s",1,"$a");
 writefile("...","<crlf>Attribut "system" set on <date yyyy.mm.dd hh.nn.ss>     for     $a <*>",a,t);
 }
 }
What is to fix here?
Please help :(

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: two foreach sections do not want funktion one after anot

Post by SkyFrontier »

First and quick guess: why not processing all actions at once for each item?
I'll take a look at this anytime soon. I hope.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

zakhar
Posts: 179
Joined: 08 Sep 2010 21:13

Re: two foreach sections do not want funktion one after anot

Post by zakhar »

SkyFrontier wrote:First and quick guess: why not processing all actions at once for each item?
I'll take a look at this anytime soon. I hope.
Yes, it was first time so as I wrote this script, in one foreach section,
but I got that bad result described above (the system attribute is not set on all folders)
and deсided to divide the copying and the attribute setting from each other.

zakhar
Posts: 179
Joined: 08 Sep 2010 21:13

Re: two foreach sections do not want funktion one after anot

Post by zakhar »

After some clicking around I think this topic can be marked as solved - I have found the circumstances,
that prevent the script to function properly:
- Before I run the script I found the folders, that will undergo the script influence, in the search tab.
So that the search results tab contains all that folders, which will have another icon and system attribute set.
the search results tab and tree must be closed before starting the script to avoid the partial failures of attrstamp().
The script commands based on quicksearch() and attrstamp interfere with the the open search results tab,
which is trying to refresh its search results after each iteration of the script.

Post Reply