I would like to use the win32 API to create an hidden file on Windows OS. It seems impossible using JS / Node.js.
With Python, importing the API, it is possible (using SetFileAttributes routine and FILE_ATTRIBUTE_HIDDEN parameter).
So how can I link a Python script to the main JS code for my Firefox add-on? Can you please give me some reference about this matter? I've found nothing on the web.
XPCOM is going to be deprecated. While this can be accomplished with nsIFile
I don't show it here because the performance is worse for the main thread. The recommended way for file system access right now is `OS.File.
https://developer.mozilla.org/en-US/docs/JavaScript_OS.File/OS.File_for_the_main_thread
This is how you do it with OS.File:
OS.File.setPermissions(
OS.Path.join(OS.Constants.Path.desktopDir, 'my hidden file.txt'),
{
winAttributes: {
hidden: true
}
}
)
.then(x => console.log('success:', x), y => console.error('failure:', y));
This will set the file on the deskto named my hidden file.txt
to be hidden. Here are the other winAttributes
:
Rename or create the file to have a .
as the first chracter in its name and it is hidden. Using OS.File this is done with the OS.File.move
function as rename is just a move on the file system:
OS.File.move(
OS.Path.join(OS.Constants.Path.desktopDir, 'my hidden file.txt'),
OS.Path.join(OS.Constants.Path.desktopDir, '.my hidden file.txt')
)
.then(x => console.log('success:', x), y => console.error('failure:', y));
This will rename, and thus making it hidden, the file on the desktop from my hidden file.txt
to .my hidden file.txt
.
If you need to tap into the platform APIs, no need for python. We have js-ctypes:
Here are some docs on js-ctypes:
https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/Standard_OS_Libraries
And here is a library/collection of type and function declarations:
https://github.com/Noitidart/ostypes/issues/1#issuecomment-199492249
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.