Working for both files and directories.