1

Forfiles with swedish characters don't work smothless...

I use a Swedish computer and the Forfiles treat swedish characters very strange. It can treat one instans correct and in the next be stupid. I have struggled with this problem for a long time and I think I have found a solution and my experience (none) tells me that it is the different operations in the forfiles that make it tough.

I have to use CHCP 65001 in my batch file to make it work. All forfiles work with this codepage except for the CALL. Then it gets into trouble.

My solution then was to change just that part to CHCP 1252. Didn't work perfectly, but when I took it all and directed it into a "some textfile.txt" file then all of a sudden everything works. Now I can use swedish characters in foldernames.

It seems that the CALL argument needs a special codepage to work, but using it on the rest of the code will fail...

Have one question though: Why does it behave this strange and why do I need to put an >myfile.txt at the end to make it work?

` CHCP 65001

forfiles /S /m * /c "cmd /c if @isdir==TRUE COPY myfile.bat @path"`

(This works even if the folders have swedish characters (åäö), but will fail using codepage 1252. Myfile.bat is placed in every folder and builds an html page of the folders content when is CALLed below).

` CHCP 1252

forfiles /S /m "myfile.bat" /c "cmd /c CALL @path" >> some textfile.txt`

(This will fail using codepage 65001, but works perfect with codepage 1252. It need the `>some textfile, without it, it will fail. Build the pages in each folder.)

DEL some textfile.txt

(The file is deleted since it is just garbage (Strange that I need this file))

CHCP 65001

(Changing back to codepage 65001 to make everything else work. Below code builds a linkpage to every folder found and is the same on every page being created.)

forfiles /S /m * /c "cmd /c if @isdir==TRUE ECHO @path" >>anotherfile.txt

(Thank you for all of your answers. I will rebuild it now when I know a little bit more. Small stepps, small stepps... )

  • 1
    Support for code page 65001 in the console is relatively new and still [a work in progress](https://blogs.msdn.microsoft.com/commandline/2018/11/15/windows-command-line-unicode-and-utf-8-output-text-buffer/), and older programs may not have been updated to support it. – Raymond Chen Feb 06 '19 at 14:25
  • Why do you use `forfiles`? The only reason for using `%SystemRoot%\System32\forfiles.exe` instead of internal command `for` is on using `forfiles` option `/D`. In all other cases `for` is the better choice. For example run in a Windows command prompt window `for /F "delims=" %I in ('dir /AD /B /S "%ProgramFiles%" 2^>nul') do @echo %~sI`. This command line outputs all directories including those with hidden attribute set found in program files directory using __short__ name of each found folder. Your character encoding problem should not occur at all by using short full qualified folder name. – Mofi Feb 06 '19 at 18:06
  • __Short__ names in 8.3 format consist of only ASCII characters. Run a command with `/?` as parameter in a command prompt window to get displayed its help. Try that out with `forfiles /?`, `for /?`, `dir /?` and `call /?`. The command `help` outputs a list of [Windows Commands](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands) documented better on [SS64.com - A-Z index of the Windows CMD command line](https://ss64.com/nt/). – Mofi Feb 06 '19 at 18:17

0 Answers0