Coder Social home page Coder Social logo

Comments (4)

GeeLaw avatar GeeLaw commented on May 17, 2024 7

@driver1998 They do not mean anything outside Win32. Within Win32, they're not limited to command line apps.

The reason that NUL doesn't do anything is because it's the null device (equivalent to /dev/null in *nix parlance). If you try type con, it echos the console input. If you try type con >prn, it copies console input to the printer.

The reason that you can access these files using \\.\ is detailed in the aforementioned documentation ("Win32 Device Namespqces"), because it doesn't try to resolve predefine aliases, and the call to \\.\d:\test\nul is accessing the device driver implementing D: namespace (which happen to be file system).

The bottom line is that one can always create files with reserved names, but it's not going to play well with the vast majority of Win32 programs. For old-timers, the need of these special handlings arises from compatibility requirements. For newer programs, one can regard the need of using \\.\ syntax as an explicit request to opt of the usual behavior in danger of making a mess.

from windows-dev-performance.

bitcrazed avatar bitcrazed commented on May 17, 2024 1

Sorry - this is a 30+ year old platform limitation with wide-ranging compatibility issues.

from windows-dev-performance.

marcosins avatar marcosins commented on May 17, 2024

Naming conventions

  • Do not use the following reserved names for the name of a file: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended.
  • Do not end a file or directory name with a space or a period. Although the underlying file system may support such names, the Windows shell and user interface does not. However, it is acceptable to specify a period as the first character of a name. For example, .temp.

From a Raymond Chen blogspot (2003):

Why do these magic files exist in every directory?
Answer: Because DOS 1.0 didn’t have subdirectories. There was only one directory, which today we would call the root directory, but back then, since there was no such thing as a subdirectory, there was no need to talk about directories in the first place, much less give the only one you have a name. It was just called “the files on your disk”. If magic files didn’t work in subdirectories, then when you tried to, for example, chdir into a subdirectory and then run the assembler, you wouldn’t be able to type “NUL” as the filename and get the magic.

from windows-dev-performance.

driver1998 avatar driver1998 commented on May 17, 2024

Do these files actually mean anything outside of Win32 command line apps (or more specifically, CMD)? Most of the time they are just "reserved" and doesn't do anything.

And this limitation only exists on Win32 subsystem, you can easily create a file named NUL or CON in WSL, heck you can even open them in a Win32 app using UNC path.
image

from windows-dev-performance.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.