Windows CE 5 Batch File Caveats

If you find yourself in the unlucky position to have to write some batch files for the Windows CE5 version of cmd.exe (called Pocket CMD v 5.0) you might be interested in these peculiarities I stumbled across today:

  • IF EXIST foldername GOTO label

    This will not tell you for real if a folder called "foldername" exists and jump to "label" if it does. Instead, this will always fail and never jump to the designated target label. You can try this yourself with


    If this output were true, I'd wonder where the Pocket CMD that had issued the command came from.

    You need to check for a file contained in that folder with IF EXISTS, which will work fine. If you do not know a file name to check for - for example if you want to check if a removable storage card is inserted, you can check for the "nul" file which will always exist on a FAT formatted drive, according to Microsoft Knowledge Base Entry #65994

  • IF ERRORLEVEL 10 GOTO fatalError

    This will not jump to the "fatalError" label in case the program that last finished with an exit code of 10 or above.

    Instead you will get an error message "Bad errorlevel conditional". In the German localization of CE5 this is even better: "Ung├╝ltige Bedingung in Fehlerebene" and proves that the person who translated this had no idea what the message meant. The problem in fact is, that the Pocket CMD only allows single digit error levels!

    If you want (or rather have) to use errorlevels in your batch script, you better hope (or can control) the exit codes of the applications you'd like to query.

If I come across more things like this, I will update this post.


Karl in Bellevue, USA said…
Nothing ever dies on the Internet. :-)

I ran across your post while looking for help with Pocket CMD batch files. I was trying to check if a USB drive was plugged in; the USB drive always appears as "Hard Disk". Checking for "\Hard Disk\NUL" failed; the NUL file was never found.

I ended up with this:
echo test >"\Hard Disk\$$$temp.txt"
if exist "\Hard Disk\$$$temp.txt" goto ready

Kinda crude, but seems to be robust.

Thanks for your post on such an obscure topic; it answered some of my questions and aimed me in the right direction.

Matt said…
Thank you so much! I was trying to see if some files had been transferred to the device. I don't even want to think how long it would have taken me to try looking for an individual file instead of the directory.

Saved me some frustration!

Popular posts from this blog

SAXParseException: -1:-1: Premature End Of File - Misleading error

Amiga 500 Restoration: A501 Memory Expansion

Amiga 500 Restoration: Mouse and Mainboard Maintenance