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... )