Failed to remove file from simple batch

I have a batch file containing this code:

del /F /S /Q /A "debug.properties"
del /F /S /Q /A "context/security/preauth/projectid-source/header/projectid-source.xml"
del /F /S /Q /A "context/compatibility/readme.txt"
del /F /S /Q /A "archived_logs"
del /F /S /Q /A "ai-license-add-in-IrsProjectManagement.bin"
del /F /S /Q /A "context/security/preauth/projectid-source/header/projectid-source.properties"
del /F /S /Q /A "debug.properties.DSPROD"
del /F /S /Q /A "context/security/preauth/projectid-source/header"

      

When I run the package from the command line, I get the error: "d" is not recognized as an internal or external command, operative program, or batch file "

It works great when I execute the del statement directly from the command line.

Any ideas what's going on here?

+3


source to share


1 answer


The batch file is obviously saved as UTF-16 slightly-endian without Byte Order (BOM).

Text editors usually indicate the file encoding somewhere. For example, the UltraEdit text editor indicates the encoding of the active file at the bottom of the status bar.

This BOM-encoded UTF-16 batch file is run in binary with bytes

00000000h: 64 00 65 00 6C 00 20 00 2F 00 46 00 20 00 2F 00 ; d.e.l. ./.F. ./.
00000010h: 53 00 20 00 2F 00 51 00 20 00 2F 00 41 00 20 00 ; S. ./.Q. ./.A. .
00000020h: 22 00 64 00 65 00 62 00 75 00 67 00 2E 00 70 00 ; ".d.e.b.u.g...p.
00000030h: 72 00 6F 00 70 00 65 00 72 00 74 00 69 00 65 00 ; r.o.p.e.r.t.i.e.
00000040h: 73 00 22 00 0D 00 0A                            ; s."....

      

Since a NULL byte is interpreted as the end of the line by cmd.exe , the command to run is simply d , which is unknown.



Convert the file from UTF-16 to ASCII in a text editor ("Save As" option) or

type test_1b.bat > test_1b_ascii.bat

      

as suggested by Ryan Bemrose and the batch file will start working.

Batch files are typically stored in ASCII files in North America and Western Europe using an OEM code page, such as code page 850 (OEM multilingual Latin I) or code page 437 (OEM US), not Windows code page 1252 as usual used for single-byte encoded text files. The code page used for the batch file depends on the local settings for non-Unicode files in the console. The code page does not matter as long as the batch file only uses characters with a code value less than 128, that is, the batch file is a real ASCII file.

+1


source







All Articles