0

I'm in a situation where there are well over 2500 items in a folder and about 500 are relevant which all follow the same naming convention which is integer.string e.g. 700.joesmith or 2000.Annieuser

Is there a way via CMD line or PowerShell to isolate specific files that follow a certain naming convention. I've been able to do so using findstr before as a basic solution but using literal search terms rather than formats so am thinking PowerShell would be the solution but I'm only a beginner.

I'm hoping there may be a way otherwise I'll happily go through long road if needs be.

Thanks in advance.

morrisstu
  • 99
  • 1
  • 1
  • 9
  • 1
    In PowerShell: `Get-ChildItem "C:\myfolder" | Where-Object { $_.Name -match "\d+\..+" }`. Warning: edge cases. Regex means _1 or more digits, followed by a dot, followed by anything_. – sodawillow Jan 03 '17 at 18:38
  • Thanks @sodawillow however could you provide an explanation as to the script. If it works that's great however if I ever need to expand on it or alter I won't have a clue. – morrisstu Jan 03 '17 at 18:40
  • 1
    I suggest you use this as a starting point and then come back, [edit your question](http://stackoverflow.com/posts/41450041/edit) and add some code in it so we can help you tweak it. – sodawillow Jan 03 '17 at 18:41
  • 1
    That's perfect, I get a fair bit so I'll use it as a starting point and do as you say if needs be. – morrisstu Jan 03 '17 at 18:43

1 Answers1

1

Use Get-ChildItem with the -Filter parameter. This performs filtering in the filesystem driver, and improves performance, versus filtering using PowerShell's Where-Object command.

This StackOverflow post goes into great detail about how to use -Filter effectively: Powershell, File system provider, Get-ChildItem filtering... where are the official docs?

Community
  • 1
  • 1