You are not logged in.
In batch dir /b, wildcard ? unavoidably snags some unacceptable results;
therefore in batch I need to use instead an equivalent powershell command.
This line
>powershell "dir -directory -include ???-?? |select fullname"
gives correct results.
However, they are preceded by two preamble lines
FullName
--------
bad for the further processing.
Question is how to get clean output
(not how to clean the output).
Last edited by be (25 Jan 2019 04:44)
Offline
You can remove those lines by piping to format-table -HideTableHeaders
so
PS C:\> dir -directory -include ???-?? | select fullname | format-table -HideTableHeaders
However it's important to realise that while the above is fine as a way to format things for display on the screen, in PowerShell everything is an object and that is a very very useful thing, once you pipe the output through format-table you have a bunch of strings with spaces and tabs and all kinds of crud that becomes difficult to work with, it becomes like going back to CMD.
A better approach - you can put the list of files into a variable with:
$files = dir -directory -include ???-?? | select fullname
And then display the list with:
$files
Even though this looks like one simple column of strings, it is not, we are still working with an object that can have multiple properties and methods, it just happens that by default it only displays the FullName property
To display the list without any header line, explicitly request just that one property:
$files.FullName
I think everyone starting with PowerShell thinks just give me the string I know what to do with that, but once you get used to working with objects you realise thats where all the "Power" in PowerShell is.
Offline
To answer precisely your question : select -ExpandProperty fullname
But Simon is right: if you're trying to manipulate strings, you don't have the correct mindset. Forget about batch and jump on the PowerShell bandwagon.
Offline
Reply, everything in it, is excellent.
Offline
select -ExpandProperty fullname
Good.
if you're trying to manipulate strings
I seek to avoid having to manipulate
jump on the PowerShell bandwagon
On target nonetheless. Taken to heart.
Offline
To answer precisely your question : select -ExpandProperty fullname
Good point, I didn't realise that also removed the headers - learn something new every day!
Offline