Page 2 of 3

Re: Append variable to an array ?

Posted: 27 Dec 2023 17:04
by admin
And stop mailing me.

Re: Append variable to an array ?

Posted: 27 Dec 2023 17:15
by MonkeyButt
You asked for the whole script, as to what may be wrong ?

Re: Append variable to an array ?

Posted: 27 Dec 2023 19:18
by admin
Your script makes no sense and is full of errors. No idea what you want to achieve. Shrug. Try to talk about your goals.

Re: Append variable to an array ?

Posted: 27 Dec 2023 20:37
by highend
Maybe, just maybe... You read up the syntax of implode()?
The second parameter is the variable name of the list to map the array to.
Does it make sense to use $i (the iterator) here?...
Why is "||" used as the separator, you aren't even assigning $gPath to the array but a single folder name, etc. etc. etc.

Re: Append variable to an array ?

Posted: 27 Dec 2023 21:25
by MonkeyButt
highend wrote: 27 Dec 2023 20:37 Maybe, just maybe... You read up the syntax of implode()?
The second parameter is the variable name of the list to map the array to.
Does it make sense to use $i (the iterator) here?...
Why is "||" used as the separator, you aren't even assigning $gPath to the array but a single folder name, etc. etc. etc.
I wanted to as you mentioned here; viewtopic.php?p=216791#p216791 to append a variable to an array. Therefore I append each iteration to the the array and that is $pArray[$i]=$iten then using implode I want to show the array as this function does and that is what I want to do. When implode() function was not just returning the array but also the function itself I wanted to know what I'm doing wrong.

$gPath is just to go to that file path, it works as I want; the || is to separate each item in the array so I can see the file paths there is no connection because realpath() doesn't ask for any other arguments as you mention any separators.

Re: Append variable to an array ?

Posted: 28 Dec 2023 03:31
by MonkeyButt
I think I may know where the problem lies; although I do have another question the native variable <allitems> returns all the sub-folders for a selected folder in my case, except; how can I get just the folder omitting the path ?

Re: Append variable to an array ?

Posted: 28 Dec 2023 08:06
by highend
Turn on Menu - Scripting - [x] Syntax Checking

You see garbage (and not the content of the array) because the implode() line is missing the trailing semicolon^^

Apart from that the whole script doesn't make sense

- Looping over a single item ($askusr does only contain (at max) one)
- If there are multiple subfolders in $iten the goto will fail
- The implode() is totally unnecessary (and wrong!), the array doesn't even contain "||"-separated entries
you could just have used text $pArray[0] as well
- If $iten would really contain more than one item you would destroy your loop when implode() maps the array to the iterator because with the next loop $i wouldn't contain it's former number anymore (you just overwrote it via implode()^^)...

It equals to (if I remove the unnecessary stuff) to:

Code: Select all

    $askusr = inputfolder("C:\","Choose Source Folder");
    $pArray[0] = $askusr;
    text implode($pArray);
<allitems> does return what's currently inside the active pane, this has nothing to do with a "selection" and it would require a loop to get only the pure folder names from it

Re: Append variable to an array ?

Posted: 29 Dec 2023 04:50
by MonkeyButt
highend wrote: 28 Dec 2023 08:06 Turn on Menu - Scripting - [x] Syntax Checking

You see garbage (and not the content of the array) because the implode() line is missing the trailing semicolon^^

Apart from that the whole script doesn't make sense

- Looping over a single item ($askusr does only contain (at max) one)
- If there are multiple subfolders in $iten the goto will fail
- The implode() is totally unnecessary (and wrong!), the array doesn't even contain "||"-separated entries
you could just have used text $pArray[0] as well
- If $iten would really contain more than one item you would destroy your loop when implode() maps the array to the iterator because with the next loop $i wouldn't contain it's former number anymore (you just overwrote it via implode()^^)...

It equals to (if I remove the unnecessary stuff) to:

Code: Select all

    $askusr = inputfolder("C:\","Choose Source Folder");
    $pArray[0] = $askusr;
    text implode($pArray);
<allitems> does return what's currently inside the active pane, this has nothing to do with a "selection" and it would require a loop to get only the pure folder names from it
I understand what your saying, including some of my mistakes. Although if one folder is selected and that folder contains sub-folders; I want to loop over those sub-folders ignoring any panes.

Re: Append variable to an array ?

Posted: 29 Dec 2023 06:46
by RalphM
And for the 2 lines of comment you needed to quote the whole post above? :whistle:

Re: Append variable to an array ?

Posted: 29 Dec 2023 09:17
by highend
I want to loop over those sub-folders ignoring any panes
Then use a foreach loop for the $ccPath?

Re: Append variable to an array ?

Posted: 30 Dec 2023 03:58
by MonkeyButt
I have a question why this line of code;

Code: Select all

$ccPath = listfolder($iten,input("Folder to Find",,,e,300,300),2,||);
the forth argument is suppose to show only the folders yet it is showing me whatever files I have as well ?

Re: Append variable to an array ?

Posted: 30 Dec 2023 08:16
by highend
The 4th arg you've used for listfolder() is ||...
You've skipped an arg for the input() part...

Apart from the fact you don't want to follow easy instructions:
Turn on Menu - Scripting - [x] Syntax Checking

Can't reproduce, the listfolder() returns only the folders inside $iten...

Re: Append variable to an array ?

Posted: 31 Dec 2023 04:31
by MonkeyButt

Code: Select all

$pArray[] = $ccPath
Should take all folders and place them into the Array and that works when I implode() but trying to access an individual item in the array $pArray[3] doesn't work ?

Re: Append variable to an array ?

Posted: 31 Dec 2023 10:57
by highend
No info about what $ccPath contains or the output of implode() looks like...

Educated guess: No ","-delimited entries in the array => Hence not a correct index access...

Re: Append variable to an array ?

Posted: 31 Dec 2023 16:03
by MonkeyButt
highend wrote: 31 Dec 2023 10:57 No info about what $ccPath contains or the output of implode() looks like...

Educated guess: No ","-delimited entries in the array => Hence not a correct index access...
$i=0; is initialized outside of the forEach loop, within the forEach I have $i+=1 and $ccPath does show the list of folders when returned then why since I'm assigning $ccPath to the array can I not just access one of the file paths using an Array index ?
You mentioned in a previous post how to use arrays in XY, it read straight forward but it's not indexing.

Code: Select all

$ccPath = listfolder($iten,*,2,||);
$pArray[$i] = $ccPath;
}