CMD: '■m' is not recognized as an internal or external command - windows

I am trying to get a batch file to work. Whenever I attempt to run a .bat the command line returns '■m' is not recognized... error, where "m" is the first letter of the file. For example:
md c:\testsource
md c:\testbackup
Returns
C:>"C:\Users\Michael\Dropbox\Documents\Research\Media\Method Guide\Program\test
.bat"
C:>■m
'■m' is not recognized as an internal or external command,
operable program or batch file.
Things I have tried:
Changing Path variables, rebooting, etc.
Changing file directory (i.e. run from C:)
Running example files from web (like above) to check for syntax errors.
Thanks

What text editor are you writing this in? It seems like your text editor may save the file as UTF-16 encoded text, which cmd.exe can't handle. Try setting the "coding"/"file encoding" to "ANSI" when saving the file.
This results in the first byte being a byte-order-mark (telling other editors how to process the file), and cmd.exe can't deal with this.

In addition to the approved answer I would add the case where is a PowerShell command the one that creates the file... PowerShell comes by default with the UTF-16 encoding.
To solve your problem then, force the file encoding lie this: | out-file foo.txt -encoding utf8
Answer based on this other answer.

In windows 10 I had the same issue.
Changing the character set to UTF-8 made it worse.
It worked correctly when I selected Encoding as UTF-8-NO BOM.

Related

In Windows 10 how do I rename a file to a filename that includes a character with an umlaut?

I'm on Win10 and I have a .bat file to rename a bunch of files. Some of the entries need to be renamed to a non-English name, e.g.
RENAME "MyFile1.txt" "Eisenhüttenstadt.txt"
However, when I run this, the 'ü' comes out as something else, other characters with an umlaut also are replaced by different characters.
I've tried saving the .bat file in Notepad with Unicode and UTF-8 encoding but then Windows doesn't recognise the command when I try to run it.
I've read this and other similar issues but not found a solution, surely it's simple when you know how?
Any suggestions?
The default code page in the console is 437(USA) or 850(Europe), which does not support characters with umlaut, so you must change this to 1252(West European Latin). So, use Chcp command in the beginning of your batch file to change it, like this:
Chcp 1252
Example:
image via http://www.pctipp.ch/tipps-tricks/kummerkasten/windows-7/artikel/windows-7-umlaute-in-batch-dateien-55616/
Sources:http://ss64.com/nt/chcp.html , http://www.pctipp.ch/tipps-tricks/kummerkasten/windows-7/artikel/windows-7-umlaute-in-batch-dateien-55616/ (The article says for Windows 7 but this applies for Windows 10 too)

In Windows, how do I find all files in a certain directory that are encoded using unicode?

I am having trouble searching a large directory of files for a string. The search command I'm using is skipping any file encoded in Unicode. I want to find all the files in this directory that are encoded in Unicode. I am on Windows XP.
Thank you!
You don't know encoding before you open a file and read from it. So you will enumerate directory files, then go through the list, open and check either BOM or the content itself (such as certain amount of heading bytes).
The find command in Windows supports Unicode text files. findstr doesn't.
You can do it with my script below, the input does not care what encoding, as far as you specify the output encoding like this -Encoding ASCII.
Goto the Dir you want cd c:\MyDirectoryWithCrazyCharacterEncodingAndUnicode
Fire this script away!
Copy and past the script in your Powershell windows, you get the idea just play with it to fix the syntax
foreach($FileNameInUnicodeOrWhatever in get-childitem )
{
$tempEncoding = (Get-Content -encoding byte)
write-output $FileNameInUnicodeOrWhatever "has encoding" $tempEncoding
// [System.Text.Encoding]::$result
}
If you want to further resolve issues with not being able to find files because of encoding, change the encoding type

my.bat not recognized as an internal or external command, operable program or batch file

When I logon to this Windows 2008 R2 Server and launch a CMD window, the default directory is:
C:\Users\SVC_asl2trim>
So I added this to the PATH and then I issued:
C:\Users\SVC_asl2trim>set path
Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32
\WindowsPowerShell\v1.0\;D:\Program Files\Hewlett-Packard\HP TRIM\;C:\Users\SVC_
asl2trim\
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
C:\Users\SVC_asl2trim>
I have a small .bat file in that directory above but I keep getting:
my.bat not recognized as an internal or external command, operable program or batch file
This is maddening. I do this so infrequently .... I know there is some trick I am forgetting.
My stupid mistake...
Credit should go to Dennis for verifying that my.bat should work but as he surmised, it was not named that. I thought I had renamed it correctly from my.txt to my.bat but the problem was that it was actually named my.bat.txt ! Fixing that was key to this problem.
I was getting this error because my batch file was not ascii encoded; it was utf-8.
Since UTF and UCS often contain a BOM at the start of the file, make sure to save it as ASCII or UTF-8 without the BOM.
If you really need an alternate encoding, making the first line blank can sometimes work (for me the UTF-8 BOM doesn't stop execution, but the USC-2 one does). Both will print an error message from the first line, so it's not an ideal solution.

International characters in a batch file

Hey, I'm having some problems writing a batch file where I need to specify some file paths containing international characters (the norwegian letter 'ø' to be exact).
For example, the filename axporteføljedb.vbp (which looks normal in notepad) turns into axportef°ljedb.vbp on the command line, which the system then goes on to complain about not finding.
Any suggestions?
It will work if you save your batch file as ANSI with a Norwegian character set (with Notepad++ for example). Then, in the cmd, when you want to run your batch file, first change the code page to something that supports Norwegian: chcp 1252 (in the console).

Why is there a difference between the encoding of the Windows Command Prompt vs. a batch file?

For example, suppose I have a batch file called 'test.cmd' and it simply contains:
echo %1
I can call this directly from the command prompt with 'test.cmd some¬arg' and the result is that the string 'some¬arg' is printed.
However if I place that same call in a second batch file, called 'tester.cmd' for the sake of argument, and I call this from the command prompt the result is that the string 'some%arg' is printed.
What is it that messes up the encoding and how do I get around it? I am sure I've fixed this before, but I can't remember how...
Thanks!
This is because your batch file is encoded in a different code page than cmd.exe is currently in.
In western default configurations, cmd.exe starts in CP850, but text editors usually work in CP1252 (what is often wrongly referred to as Latin-1 or ISO-8859-1).
The characters "¬" and "¼" share the same character code in these two code pages, "BC".
The solution is simple. Either encode your batch file in code page 850, or switch cmd.exe to code page 1252 by issuing chcp 1252.

Resources