Append variable to an array ?
-
- Posts: 19
- Joined: 21 Dec 2023 01:31
Re: Append variable to an array ?
You asked for the whole script, as to what may be wrong ?
-
- Site Admin
- Posts: 59751
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Append variable to an array ?
Your script makes no sense and is full of errors. No idea what you want to achieve. Shrug. Try to talk about your goals.
FAQ | XY News RSS | XY Twitter
Re: Append variable to an array ?
Maybe, just maybe... You read up the syntax of
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.
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 or paypal_donate (at) stdmail (dot) de
-
- Posts: 19
- Joined: 21 Dec 2023 01:31
Re: Append variable to an array ?
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.highend wrote: ↑27 Dec 2023 20:37 Maybe, just maybe... You read up the syntax ofimplode()
?
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.
$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.
-
- Posts: 19
- Joined: 21 Dec 2023 01:31
Re: Append variable to an array ?
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 ?
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 (
- If there are multiple subfolders in
- The
you could just have used
- If
It equals to (if I remove the unnecessary stuff) to:
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 entriesyou 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 itOne of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de
-
- Posts: 19
- Joined: 21 Dec 2023 01:31
Re: Append variable to an array ?
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.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
thegoto
will fail
- Theimplode()
is totally unnecessary (and wrong!), the array doesn't even contain "||"-separated entries
you could just have usedtext $pArray[0]
as well
- If$iten
would really contain more than one item you would destroy your loop whenimplode()
maps the array to the iterator because with the next loop$i
wouldn't contain it's former number anymore (you just overwrote it viaimplode()
^^)...
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 ?
And for the 2 lines of comment you needed to quote the whole post above?
Ralph
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)
Re: Append variable to an array ?
Then use aI want to loop over those sub-folders ignoring any panes
foreach
loop for the $ccPath
?One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de
-
- Posts: 19
- Joined: 21 Dec 2023 01:31
Re: Append variable to an array ?
I have a question why this line of code; the forth argument is suppose to show only the folders yet it is showing me whatever files I have as well ?
Code: Select all
$ccPath = listfolder($iten,input("Folder to Find",,,e,300,300),2,||);
Re: Append variable to an array ?
The 4th arg you've used for
You've skipped an arg for the
Apart from the fact you don't want to follow easy instructions:
Turn on Menu - Scripting - [x] Syntax Checking
Can't reproduce, the
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 or paypal_donate (at) stdmail (dot) de
-
- Posts: 19
- Joined: 21 Dec 2023 01:31
Re: Append variable to an array ?
Code: Select all
$pArray[] = $ccPath
Re: Append variable to an array ?
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...
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 or paypal_donate (at) stdmail (dot) de
-
- Posts: 19
- Joined: 21 Dec 2023 01:31
Re: Append variable to an array ?
$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;
}