I\'m iterating a directory of files and was wondering if it\'s possible to test if a file is hidden or not. Currently, I\'m just checking if file starts with a \'.\' or not. Thi
The regular expression to effectively detect hidden files and directory path in Unix would be a bit more complex owing to the possibility of their existence within a long path string.
The following tries to take care of the same.
/**
* Checks whether a path starts with or contains a hidden file or a folder.
* @param {string} source - The path of the file that needs to be validated.
* returns {boolean} - `true` if the source is blacklisted and otherwise `false`.
*/
var isUnixHiddenPath = function (path) {
return (/(^|\/)\.[^\/\.]/g).test(path);
};