Find all files that include a space before file name

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”



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



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

where {($ -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.

I think he meant " " not the actual phrase.

How about

ls -r ' *'


Yes, sorry for bad explain earlier.

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

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

$string = “yeah”
$string.StartsWith(" ")

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



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’}

thanks Jarkko Vepsäläinen!


You’re welcome, glad you got this work.