Append variable to an array ?

Discuss and share scripts and script files...
admin
Site Admin
Posts: 60622
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Append variable to an array ?

Post by admin »

And stop mailing me.

MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post by MonkeyButt »

You asked for the whole script, as to what may be wrong ?

admin
Site Admin
Posts: 60622
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Append variable to an array ?

Post 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.

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Append variable to an array ?

Post 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.
One of my scripts helped you out? Please donate via Paypal

MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post 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.

MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post 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 ?

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Append variable to an array ?

Post 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
One of my scripts helped you out? Please donate via Paypal

MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post 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.

RalphM
Posts: 1935
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: Append variable to an array ?

Post by RalphM »

And for the 2 lines of comment you needed to quote the whole post above? :whistle:
Ralph :)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Append variable to an array ?

Post by highend »

I want to loop over those sub-folders ignoring any panes
Then use a foreach loop for the $ccPath?
One of my scripts helped you out? Please donate via Paypal

MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post 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 ?

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Append variable to an array ?

Post 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...
One of my scripts helped you out? Please donate via Paypal

MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post 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 ?

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Append variable to an array ?

Post 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...
One of my scripts helped you out? Please donate via Paypal

MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post 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;
}

Locked