Author Posts

July 3, 2017 at 6:56 pm

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!

July 3, 2017 at 7:08 pm

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

July 3, 2017 at 8:28 pm

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.

July 3, 2017 at 8:52 pm

I think he meant " " not the actual phrase.

July 3, 2017 at 11:40 pm

How about

ls -r ' *'

July 4, 2017 at 5:45 am

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

July 10, 2017 at 2:25 pm

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

July 10, 2017 at 2:25 pm

thanks Jarkko Vepsäläinen!

July 10, 2017 at 4:36 pm

Hi

You're welcome, glad you got this work.

Regards

Jarkko