My ultimate goal is to set up a script on a Windows server that will find any files in a given folder that contain non-printable, non-ASCII characters, and move those files to another folder.

To find the files, I was thinking I could use something like this, but it doesn't work:

findstr /m /r /c:"[^\x20-\x7e\r\n]" *.txt

To simplify the problem, let's say I have two text files, 1.txt and 2.txt that contain "abcdefg" and "defghijk", respectively. This command will return "2.txt" in the output as expected:

findstr /m /r /c:"[^a-g]" *.txt

However, substituting the hex codes \x61 and \x67 for 'a' and 'g' fails with no output:

findstr /m /r /c:"[^\x61-\x67]" *.txt

It doesn't seem like you can use hex values in a character class with the findstr utility. How else can I accomplish my goal? Is it possible to do with windows batch scripting?

  • 1
    Findstrs RegEx capabilities are rather limited. Better use J-/vbscript or Powershell for this. But in times of Unicode everwhere your approach doesn't seem promising.
    – LotPings
    Apr 27, 2018 at 22:04
  • This is a bandaid for a legacy app that chokes on those characters, so I was hoping for a quick and simple solution, but I guess I've got some coding to do.. False positives are not too big of a concern though, if that makes a difference. Apr 27, 2018 at 22:44


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.