Add Asterisks

Welcome Forums General PowerShell Q&A Add Asterisks

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 3 months ago.

  • Author
  • #83521

    Points: 0
    Rank: Member


    Let's say I have a thousand files within C:\Test 1\
    File (1).txt
    File (2).txt
    File (999).txt
    File (1000).txt

    I want to read, sort and export those to another textfile. I've accomplished the above through these two commands:

    Set-Location -Path C:\"Test 1"
    Get-ChildItem *.txt | Sort-Object {$_.BaseName -replace "\D+" -as [Int]} | Select-Object -ExpandProperty Name > !files.txt

    All filenames are now within !files.txt, neatly sorted. Ultimatively I want it so that each entry within !files.txt is headed by an asterisk *

    So like this (within !files.txt):
    *File (1).txt
    *File (2).txt
    *File (999).txt
    *File (1000).txt

    Is there a way to do this? Thanks.

  • #83524

    Points: 41
    Rank: Member
    Get-ChildItem *.txt | Sort-Object {$_.BaseName -replace "\D+" -as [Int]} | Select-Object -ExpandProperty Name | 
    ForEach-Object {Write-Output "*$_" | Out-File '!files.txt' -Append -NoClobber}
  • #83533

    Points: 0
    Rank: Member

    That worked perfectly. Thank you very much.

The topic ‘Add Asterisks’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort