Posts: 184
Threads: 22
Joined: Mar 2023
Reputation:
12
Happy holidays. I've sniffed around the site and can't find an alphabetizing routine. I doesn't have to be fast - I just need it to reorder some short files holding song titles. Any ideas for a guy looking for a simple sorter? Thanks!
Posts: 731
Threads: 30
Joined: Apr 2022
Reputation:
43
If I was still trying to peddle PowerShell scripts, I'd say use a text file and have PowerShell sort it for you and put it into a sorted file to be read. Or, use a file and have PowerShell output to stdout and use pipecom to read it in.
Tread on those who tread on you
Posts: 731
Threads: 30
Joined: Apr 2022
Reputation:
43
12-21-2023, 07:46 PM
(This post was last modified: 12-21-2023, 07:59 PM by SpriggsySpriggs.)
For working in PowerShell:
I have formatted them as if you are running it from inside a SHELL call in QB64. The carets (^) are needed to escape the pipe (|) characters. If you are running it already in PowerShell, you would get rid of "PowerShell -NoProfile" and the carets.
If you want the directory listing of all text files sorted (PowerShell):
Quote:PowerShell -NoProfile Get-ChildItem -Filter *.txt ^| Select Name -ExpandProperty Name ^| Sort-Object > sorted.txt
If you already have a file with content inside of it (PowerShell):
Quote:PowerShell -NoProfile Get-Content -Path examplefile.txt ^| Sort-Object > sorted.txt
P.S
The "-NoProfile" switch is necessary for PowerShell because there are profile scripts that are loaded when it is started that slow down execution considerably. "-NoProfile" tells it to ignore user settings which speeds up the call.
P.P.S
The redirect to sorted.txt is only necessary if you are not using pipecom. Without pipecom, you won't have access to the direct stdout handle. With it, you would remove that redirect and just grab the raw stdout from the call.
Tread on those who tread on you