Here is a small script I wrote that recursively scan a directory without some parent-subdirectories and extracts some attributes of the files within it.

@echo off
echo Path,Name,Extension,Size > filelist.txt
for /f "delims=" %%i in ('dir D:\שער /A:-d /s /b ^| findstr /l /i /v ^/c:"קקק" ^/c:"ttt"') 
do echo %%~dpi,%%~ni,%%~xi,%%~zi >> filelist.txt

The problem is that findstr doesn't support Unicode chars (hebrew in this case, for /f does if you change the console font).

What is the PowerShell version of this script (assuming that PS loop does support unicode chars) ?

Thank you

  • 1
    Just a nitpick: from the title it looks like UTF is about the conetnts of the files, since UTF is a file encoding/format. IMHO it would be better to say "Unicode paths" instead of "UTF folders/files". – Nathan.Eilisha Shiraini Jul 5 '17 at 7:16
  • There are no "UTF" chars. UTF-8/16/32 are encoding schemes for Unicode and Windows uses UTF-16. findstr doesn't support Unicode but find does – phuclv Jul 5 '17 at 7:35

Assuming that your findstr command is used to search the files content for the קקק text, here is the PowerShell code equivalent:

Set-Content -Path 'filelist.txt' -Value 'Path,Name,Extension,Size' -Encoding UTF8

foreach( $file in (Get-ChildItem -File -Path 'C:\Temp\שער' -Recurse) )
    $nameCount = Get-Content -Path $file.FullName -Encoding UTF8 | Select-String -Pattern 'קקק' | Measure-Object | Select-Object -ExpandProperty Count

    if( $nameCount -gt 0 )
        $line =  $file.DirectoryName + ',' + $file.BaseName + ',' + $file.Extension + ',' + $file.Length
        Add-Content -Path 'filelist.txt' -Value $line -Encoding UTF8
| improve this answer | |

I had a similar problem with findstr, and solved it by using Select-String instead of findstr.

cat .\log*.txt | findstr -I Error was buggy, but cat .\log*.txt | Select-String -Pattern 'Error' was working fine.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.