Q:

How does nul work when a file called nul exists

If nul can never be a file in Windows, what if it a file called "nul" was created in all the directorys using a OS that doesn't have the same rules for nul. Would data be written to nul if for example 'echo 1234>nul' was performed in CMD or would it be discarded?

A:

if for example 'echo 1234>nul' was performed in CMD or would it be discarded?

It would be discarded.
Note the following example which creates a file called nul then calls echo 5678>nul. The existing file nul is not changed.
C:\temp>echo 1234>\\?\%cd%\nul

C:\temp>dir /b /a-d
nul

C:\temp>type \\?\%cd%\nul
1234

C:\temp>echo 5678>nul

C:\temp>type \\?\%cd%\nul
1234

C:\temp>del \\?\%cd%\nul

C:\temp>

For details about the \\?\ syntax see Win32 File Namespaces.

A:

Nul is not a reference to a file, it is part of Windows and when >nul is performed, it isn't writing it the the file nul, but instead it's just being ignored

