Search code examples
c++windowsfilestreamntfs

Using a file PATH with a colon in Windows file system


What does the colon in the PATH (for example "a:data.dat") mean in Windows file system.

In the following C++ code:

ofstream outfile;
outfile.open("a:data.dat");

I'm using Windows OS and It works fine when reading/writing but I cannot find the "data.dat" part in the name of the file stored. There is only a file named "a" with 0 bytes after writing.


Solution

  • The NTFS file system supports multiple File Streams per file, where the file name and stream name are separated by :. Every file has a default unnamed stream, but can also have additional named streams.

    What you describe sounds like you have created a file a that contains a secondary stream named data.dat, and then you are writing your data to that stream.

    When you later try to read/view the file, if the default stream is accessed instead of the data.dat stream, it will seem like no data had been written to the file at all. But it really was written to, and you would need to open the data.dat stream in order to read its data.

    FYI, most apps don't know anything about these secondary file streams, so they only read/write the default stream. Which would explain the symptom you are experiencing.