Hidden File


#1

How do I create a hidden file, Windows and Mac? Is there a juce way of doing this?


#2

Haven't really got a cross-platform way of doing that, as I think it depends on the filename starting with a dot on some platforms, and on file attributes on others..


#3

Should I add File::makeHidden() that does this or would you do it? You already have isHidden()

On windows side:

bool File::setIsHidden (bool shouldBeHidden) const
{
    const DWORD oldAtts = WindowsFileHelpers::getAtts (fullPath);
    if (oldAtts == INVALID_FILE_ATTRIBUTES)
        return false;
    const DWORD newAtts = shouldBeHidden ? (oldAtts |  FILE_ATTRIBUTE_HIDDEN)
                                                       : (oldAtts & ~FILE_ATTRIBUTE_HIDDEN);
    return SetFileAttributes (fullPath.toWideCharPointer(), newAtts) != FALSE;
}

On others would renaming the file with a '.' at the beginning do it?

BTW, how do you rename a file?


#4

This is exactly why I wouldn't add a method like that. If the method had to work by changing the file name then that's something the user would need to handle in their own code.


#5

Renaming is with the File::moveFileTo call.  (Move and rename are closely related operations when the file is beig moved on the same partition). http://www.juce.com/doc/classFile#a43a7e37203ed65b036a2c54f0f260857


#6

Would it be possible to add a way in the File class to set the hidden flag of any file on Windows and Mac OS X ? Thanks in advance !


#7

Not really. On Windows it'd be doable, but I think on posix systems a file is just hidden if you put a dot in front of it, and it'd be a terrible API for the File class to automatically rename a file by adding a dot..


#8

Would it be possible to do it only for Windows at least ? Thanks in advance ;)