Check whether a file is writable or not
@function $file~writable
@param {string} file
@returns {boolean}
@example
// Check if 'conf/my.cnf' is writable by the current user
$file.writable('conf/my.cnf');
// => true
179859
function writable(file) {
  if (!exists(file)) {
    return writable(path.dirname(file));
  } else {
    try {
      fs.accessSync(file, fs.W_OK);
    } catch (e) {
      return false;
    }
    return true;
  }
}
82621
private function lintFile($file)
    {
        // first try to parse it
        try {
            $this->parser->parse(\file_get_contents($file));
        } catch (\Exception $e) {
            return false;
        }

        return true;
    }
351646
protected function checkFileReadable($file)
    {
        if (!file_exists($file)) {
            throw new \RuntimeException("File [$file] does not exist");
        }
        if (!is_file($file)) {
            throw new \RuntimeException("File [$file] is not a file");
        }
        if (!is_readable($file)) {
            throw new \RuntimeException("File [$file] is not readable");
        }
    }
1103813
public static function isWritable(string $path): bool
    {
        // If it's a directory, test on a temp sub file
        if (is_dir($path)) {
            return static::isWritable($path . DIRECTORY_SEPARATOR . uniqid('test_writable', true) . '.tmp');
        }

        // Remember whether the file already existed
        $exists = file_exists($path);

        if (($f = @fopen($path, 'ab')) === false) {
            return false;
        }

        @fclose($f);

        // Delete the file if it didn't exist already
        if (!$exists) {
            static::removeFile($path);
        }

        return true;
    }
182733
public function save(string $file): bool
    {
        $stat = file_put_contents($file, $this->definition->toFbp());

        if ($stat === false) {
            return false;
        }

        return true;
    }
211838
function checkIfFileWasUpdated($file)
    {
        $absoluteFilePath = ROOTPATH . $file;
        if (file_exists($absoluteFilePath)) {
            $fileExtension = pathinfo($file, PATHINFO_EXTENSION);
            $fileName = pathinfo($file, PATHINFO_FILENAME);
            $fileFullName = pathinfo($file, PATHINFO_BASENAME);
            $minifiedFileName = substr($file, 0, -strlen($fileFullName)) . $fileName . '.minified.' . $fileExtension;
            $changeDate = filectime($absoluteFilePath);
            $changeDateMinified = file_exists(ROOTPATH . $minifiedFileName) ? filectime(ROOTPATH . $minifiedFileName)
                : 0;
            if ($changeDateMinified == 0 || $changeDate < $changeDateMinified) {
                return $minifiedFileName;
            }
        }

        return null;
    }
853134
final public function hasFile($file)
	{
		$helloReflection = new \ReflectionClass($this);
		$dir = dirname($helloReflection->getFilename());

		if(file_exists($dir . '/' . $file)) {
			return $dir . '/' . $file;
		}
		return false;
	}
950715
function isJSON (file) {
  try {
    JSON.parse(file.contents.toString());
    return true;
  } catch (err) {
    return false;
  }
}
817475
protected function isConfig($file)
    {
        if (basename($file) === 'config.php' && is_file($file) && is_readable($file)) {
            $contents = file_get_contents($file);

            if ($contents && strpos($contents, 'txpcfg') !== false && file_exists(dirname($file) . '/publish.php')) {
                return dirname($file);
            }
        }

        return false;
    }
46334
protected function isValidFile($file): bool
    {
        // If there's no file we can't do anything with it...
        if (empty($file)) {
            return false;
        }

        // If the file doesn't exist, no need to try and get it.
        if (!file_exists($file)) {
            // We should probably log here...
            return false;
        }

        // If we can't read the file... Why try...
        if (!is_readable($file)) {
            // We should probably log or something here...
            return false;
        }

        return true;
    }
224432
function fileExists(file) {
    var fileExists = true;

    try {
        fs.statSync(file, function(err, stat) {
            if (err == null) {
                fileExists = true;
            } else {
                fileExists = false;
            }
        });
    } catch (e) {
        fileExists = false;
    }

    return fileExists;
}
120936
public function readConfig($file = 'config.php')
    {
        $orig_file = $file;

        if (strpos($file, '.php') != strlen($file) - 4) {
            $file .= '.php';
        }

        if (strpos($file, '/') === false) {
            $file = getcwd().'/'.$this->config_location.'/'.$file;
        }

        if (file_exists($file)) {
            // some tricky thing to make config be read in some cases it could not in simple way
            unset($config);

            $config = &$this->config;
            $this->config_files_loaded[] = $file;
            include $file;

            unset($config);

            return true;
        }

        return false;
    }
21296
function _isFile (file, callback) {

			if ("undefined" === typeof file) {
				throw new ReferenceError("missing \"file\" argument");
			}
				else if ("string" !== typeof file) {
					throw new TypeError("\"file\" argument is not a string");
				}
				else if ("" === file.trim()) {
					throw new Error("\"file\" argument is empty");
				}
			else if ("undefined" === typeof callback) {
				throw new ReferenceError("missing \"callback\" argument");
			}
				else if ("function" !== typeof callback) {
					throw new TypeError("\"callback\" argument is not a function");
				}
			else {

				lstat(file, (err, stats) => {
					return callback(null, Boolean(!err && stats.isFile()));
				});

			}

		}
215334
protected function _check_data($file = null) {
        if (empty($this->file_data)) {
            if (is_null($file)) {
                $file = $this->file;
            }

            return $this->load_data($file);
        }

        return true;
    }
939382
private function checkNotAllowedTypes($file = '')
        {
            $notAllowedTypes = $this->getNotAllowedExt();

            if ('*' === $notAllowedTypes) {
                return true;
            }

            if(is_string($notAllowedTypes))
            {
                $notAllowedTypes = (array) $notAllowedTypes;
            }

            foreach($notAllowedTypes as $type){
                if(strstr($file, $type)){
                    return false;
                }else{
                    continue;
                }
            }

            return true;
        }
1340419
def is_file_writable(test_file):
    
    p = Path(test_file)

    if p.is_symlink():
        p = p.resolve(strict=False)

    # p.is_file() throws an exception in some cases
    if p.exists() and p.is_file():
        return os.access(
            os.fspath(p),
            os.W_OK,
            effective_ids=(os.access in os.supports_effective_ids),
        )
    else:
        try:
            fp = p.open('wb')
        except OSError:
            return False
        else:
            fp.close()
            with suppress(OSError):
                p.unlink()
        return True
1137589
public static boolean canWriteFile(File file) {		
		if(file!=null && file.canWrite() && !file.isDirectory()){
			return true;
		} else {
			return false;
		}		
	}