Let's say I want to read some strings from file, and for each string I want to split it. In the end, I want to get array of arrays of strings. Here is how I try to do it:
$toArchive = "./folders.txt"
$folderList = Get-Content $toArchive | ForEach-Object { @($_.split(" ")) }
Get-Content
should return an array of strings, and for each of those strings, I expect to get another array of strings. But instead of that my folderList
is Object[]
, as if it was flattened. For example, if my input file looks like this:
Docs /home/keddad/Documents/
NotDocs /home/keddad/NotDocuments/
I get array of 4 elements:
Docs
/home/keddad/Documents/
NotDocs
/home/keddad/NotDocuments/
What am I doing wrong here?
Update: just to clarify, it is definitely array of 4 strings:
PS /home/keddad/Documents/tbackup> $toArchive = "./folders.txt"
PS /home/keddad/Documents/tbackup> $folderList = Get-Content $toArchive | ForEach-Object { @($_.split(" ")) }
PS /home/keddad/Documents/tbackup> $folderList.count
4
PS /home/keddad/Documents/tbackup> $folderList
Docs
/home/keddad/Documents/
NotDocs
/home/keddad/NotDocuments/