Find all files that include a space before file name

This topic contains 8 replies, has 4 voices, and was last updated by  Jarkko Vepsäläinen 3 months, 1 week ago.

  • Author
    Posts
  • #74189

    JetMottoGuru
    Participant

    I need help in finding all files that include a SPACE (blank space) before the actual file name.
    Please note that the Files listed below show File Number 1 & File Number 5 to have a SPACE (blank space) before the file name. I used the underline to show the space before the filename as a placeholder since the space cannot be seen when submitting this question:
    _File Number 1.txt
    File Number 2.txt
    File Number 3.txt
    File Number 4.txt
    _File Number 5.txt

    I will need to find all files that have spaces before the file name and export to a list.
    I know the following command is wrong, but it's what i have so far:

    $gci1=Get-ChildItem "C:\" -Recurse |
    Where-Object {
    $_.Name -Match "[\s]\w"}|
    Select-Object -ExpandProperty FullName |
    Out-File "c:\Review.txt"

    THANK YOU!

  • #74192

    Hi

    How about you change the current where to where {($_.name).toSubString(1) -eq (regex to space)? Just an idea not know would it work.

    Regards

    Jarkko

    • #74203

      JetMottoGuru
      Participant

      Thanks for the help. But it did not work :/ Unless I'm doing something wrong. I've included the string just like you described (IN THE CORRECT SPACE):

      where {($_.name).toSubString(1) -eq (regex to space)

      I cannot seem to find anything online like what it is I'm asking for. You would think this is a common request, especially in an enterprise environment.

    • #74206

      Ben Camareno
      Participant

      I think he meant " " not the actual phrase.

    • #74216

      Hi

      Yes, sorry for bad explain earlier.

      Try following instead. So in this case: Where {($_.Name).StartsWith(" ") -eq 'True')}

      $string = " yeah"
      $string.StartsWith(" ")
      True

      $string = "yeah"
      $string.StartsWith(" ")
      False

      I think you might pull this off also with get-childitem -filter maybe?

      Regards

      Jarkko

    • #74572

      JetMottoGuru
      Participant

      Thank you all for your contribution! I was able to complete this task by providing the following in the string:

      Where {($_.Name).StartsWith(' ') -eq 'True'}

    • #74573

      JetMottoGuru
      Participant

      thanks Jarkko Vepsäläinen!

    • #74596

      Hi

      You're welcome, glad you got this work.

      Regards

      Jarkko

  • #74212

    js
    Participant

    How about

    ls -r ' *'

You must be logged in to reply to this topic.