I'm using PowerShell to find ignored files in my Git repository that belong to a specific directory, company_logos. I'm running the following command in my project folder:
powershell Copy Edit git ls-files --ignored --others --exclude-standard | Select-String "company_logos" However, I get this error:
vbnet
Copy
Edit
Select-String : The string \company_logos\ is not a valid regular
expression: parsing "\company_logos" - Illegal \ at end of pattern.
At line:1 char:54
- ... ignored --others --exclude-standard | Select-String "company_logos"
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidArgument: (:) [Select-String], ArgumentException
- FullyQualifiedErrorId : InvalidRegex,Microsoft.PowerShell.Commands.SelectStringCommand It seems like PowerShell is interpreting company_logos as a regex pattern, and the backslashes () in the path are causing an issue.
What I’ve tried: Escaping the backslashes:
powershell Copy Edit git ls-files --ignored --others --exclude-standard | Select-String "company_logos" But I still get the same issue.
Using single quotes:
powershell Copy Edit git ls-files --ignored --others --exclude-standard | Select-String 'company_logos' This also didn't work.
Using -SimpleMatch:
powershell Copy Edit git ls-files --ignored --others --exclude-standard | Select-String -SimpleMatch "company_logos" This worked, but I want to understand why the original command failed and how to properly escape it.
Question: Why does Select-String throw the "Illegal \ at end of pattern" error in my original command? What is the correct way to search for a directory name like company_logos in this context? Any insights would be appreciated!
I'm using PowerShell to find ignored files in my Git repository that belong to a specific directory, company_logos. I'm running the following command in my project folder:
powershell Copy Edit git ls-files --ignored --others --exclude-standard | Select-String "company_logos" However, I get this error:
vbnet
Copy
Edit
Select-String : The string \company_logos\ is not a valid regular
expression: parsing "\company_logos" - Illegal \ at end of pattern.
At line:1 char:54
- ... ignored --others --exclude-standard | Select-String "company_logos"
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidArgument: (:) [Select-String], ArgumentException
- FullyQualifiedErrorId : InvalidRegex,Microsoft.PowerShell.Commands.SelectStringCommand It seems like PowerShell is interpreting company_logos as a regex pattern, and the backslashes () in the path are causing an issue.
What I’ve tried: Escaping the backslashes:
powershell Copy Edit git ls-files --ignored --others --exclude-standard | Select-String "company_logos" But I still get the same issue.
Using single quotes:
powershell Copy Edit git ls-files --ignored --others --exclude-standard | Select-String 'company_logos' This also didn't work.
Using -SimpleMatch:
powershell Copy Edit git ls-files --ignored --others --exclude-standard | Select-String -SimpleMatch "company_logos" This worked, but I want to understand why the original command failed and how to properly escape it.
Question: Why does Select-String throw the "Illegal \ at end of pattern" error in my original command? What is the correct way to search for a directory name like company_logos in this context? Any insights would be appreciated!
Share Improve this question asked Mar 19 at 4:46 CoupynCoupyn 12 bronze badges 3- Can you please first of all apply proper code formatting, because right now, about half of the above isn't displaying correctly. stackoverflow/help/formatting – C3roe Commented Mar 19 at 7:08
- I'm guessing you should have a look at learn.microsoft/en-us/powershell/module/… – C3roe Commented Mar 19 at 7:09
- This question could use some clarification and code cleanup. Every section listed "powershell Copy Edit", and then the command used, those need to be placed within code blocks, and Copy Edit dont need to be there. – NodeDad Commented Mar 22 at 16:39
1 Answer
Reset to default 0If you change directory to company_logos in the local repo before running the git-ls-files
command, you will get the relative path to ignored files in that directory without needing to pipe to select-string
. If you need the full path add --full-name
https://git-scm/docs/git-ls-files.