Check filename and avoid duplicates

@param string $wanted_filename
@param string $path
@param integer $starting_index used in renamed file

@return string cleared filename
349323
public static function checkFileName($filename, $path, $ndx = 2) {

		$filename = str_replace(
			array(' ', 'ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß'),
			array('_', 'ae', 'oe', 'ue', 'Ae', 'Oe', 'Ue', 'ss'),
			$filename);

		$filename = preg_replace('/[^0-9a-z_#,;\-\.\(\)]/i', '_', $filename);

		$path = rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;

		if(!file_exists($path.$filename)) {
			return $filename;
		}

		$pathinfo = pathinfo($filename);

		if(!empty($pathinfo['extension'])) {
			$pathinfo['extension'] = '.'.$pathinfo['extension'];
		}
		while(file_exists($path.sprintf('%s(%d)%s', $pathinfo['filename'], $ndx, $pathinfo['extension']))) {
			++$ndx;
		}

		return sprintf('%s(%d)%s', $pathinfo['filename'], $ndx, $pathinfo['extension']);
	}
593534
public static String getFilenameExtension(String path) {
        if (path == null) {
            return null;
        }
        int extIndex = path.lastIndexOf(".");
        if (extIndex == -1) {
            return null;
        }
        return path.substring(extIndex + 1);
    }
1279369
def get_exes_in_path(starts_with: str) -> List[str]:
        
        # Purposely don't match any executable containing wildcards
        wildcards = ['*', '?']
        for wildcard in wildcards:
            if wildcard in starts_with:
                return []

        # Get a list of every directory in the PATH environment variable and ignore symbolic links
        paths = [p for p in os.getenv('PATH').split(os.path.pathsep) if not os.path.islink(p)]

        # Use a set to store exe names since there can be duplicates
        exes_set = set()

        # Find every executable file in the user's path that matches the pattern
        for path in paths:
            full_path = os.path.join(path, starts_with)
            matches = [f for f in glob.glob(full_path + '*') if os.path.isfile(f) and os.access(f, os.X_OK)]

            for match in matches:
                exes_set.add(os.path.basename(match))

        return list(exes_set)
842482
function (path) {
        var name = _gpfPathName(path),
            pos = name.lastIndexOf(".");
        if (pos === _GPF_NOT_FOUND) {
            return name;
        }
        return name.substring(_GPF_START, pos);
    }
424835
public boolean isAllowed(String path) {
    for (String filter : STARTS_WITH_FILTER) {
      if (path.startsWith(filter)) {
        return false;
      }
    }
    for (String filter : CONTAINS_FILTER) {
      if (path.contains(filter)) {
        return false;
      }
    }
    return true;
  }
321851
public function baseNameFilter($path, $suffix = false)
    {
        if ($suffix) {
            $output = basename($path, $suffix);
        } else {
            $output = basename($path);
        }
        return $output;
    }
1187582
public static String getName(final String path) {

		String cleanedPath = clean(path);

		if (cleanedPath != null && cleanedPath.contains(PATH_SEP)) {

			return StringUtils.substringAfterLast(cleanedPath, PATH_SEP);

		} else {

			return cleanedPath;

		}
	}
513103
@Override
	public boolean matchPath(String path) {

		boolean match = false;
		if (StringUtils.isNotEmpty(path)) {
			match = path.endsWith(suffix);
		}
		return match;
	}
35831
def rm_file_if_exists(path, filename):
    
    _full_path = os.path.join(path, filename)
    if os.path.exists(_full_path):
        os.remove(_full_path)
    return
165143
public static function move($path, $target, $fileName, $encryption = false, $newFilename = false)
    {
        $fileNameOld    = $fileName;
        $extension      = File::extension($fileName);
        $baseName       = basename($fileName, '.' . $extension);

        if ($encryption)
        {
            mt_srand();
            $fileName = md5(uniqid(mt_rand())) . "." . $extension;
        }
        elseif ($newFilename)
        {
            $fileName = $newFilename . "." . $extension;
        }

        $i = 0;
        while (File::exists($target . '/' . $fileName))
        {
            $i++;
            $fileName = $baseName . '-' . $i . '.' . $extension;
        }
        
        File::move($path . '/' . $fileNameOld, $target . '/' . $fileName);

        return $fileName;
    }
393776
function findFile (startingPath) {
  try {
    return fs.readFileSync(startingPath, "utf8");
  }
  catch (e) {
    let fileName = path.basename(startingPath);
    let startingDir = path.dirname(startingPath);
    let parentDir = path.dirname(startingDir);

    if (parentDir === startingDir) {
      // We're recursed all the way to the root directory
      throw e;
    }
    else {
      try {
        // Search for the file in the parent directories
        return findFile(path.join(parentDir, fileName));
      }
      catch (e2) {
        // The file wasn't found in any of the parent directories
        throw ono(e,
          `Unable to find a file named "${fileName}" in "${startingDir}" or any of its parent directories.`
        );
      }
    }
  }
}
968963
function startForeverWithIndex( index, doneCB ) {
  log( 'Attempting to start ' + index + ' as daemon.');

  var config;
  var appendConfig = function(prop, value) {
    log('Adding to config: ' + prop + ', ' + value);
    if(value !== undefined) {
      config[prop] = value;
    }
  };
  done = doneCB || this.async();
  findProcessWithIndex( index, function(process) {
    // if found, be on our way without failing.
    if( typeof process !== 'undefined' ) {
      warn( index + ' is already running.');
      log( forever.format(true, [process]) );
      done();
    }
    else {
      gruntRef.file.mkdir(logDir);
      // 'forever start -o out.log -e err.log -c node -a -m 3 index.js';
      config = {
        command: commandName,
        append: true,
        max: 3,
        killSignal: killSignal
      };
      appendConfig('errFile', errFile);
      appendConfig('outFile', outFile);
      appendConfig('logFile', logFile);
      forever.startDaemon( index, config );
      log( 'Logs can be found at ' + logDir + '.' );
      done();
    }
  });
}
380530
public static function removePath($search_path)
    {
        $index = array_search($search_path, self::$search_paths);
        if ($index !== false) {
            array_splice(self::$search_paths, $index, 1);
        }
    }
110415
function fileExists( $path )
    {
        eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileExists( '$path' )", __METHOD__ );

        eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
        $rc = file_exists( $path );
        eZDebug::accumulatorStop( 'dbfile' );

        return $rc;
    }
4351
public static function copy($start_path, $copy_path, $dir_mode = 0777)
    {
        $return = mkdir($copy_path, $dir_mode, true);
        $files = self::getContent($start_path);
        foreach ($files as $file) {
            if (is_dir($start_path.DIRECTORY_SEPARATOR.$file)) {
                $return = self::copy(rtrim($start_path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file, $copy_path.DIRECTORY_SEPARATOR.$file, $dir_mode);
            } else {
                $return = copy(rtrim($start_path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file, $copy_path.DIRECTORY_SEPARATOR.$file);
            }
        }

        return $return;
    }
467214
def relpath(path, start=posixpath.curdir):
    """"""
    if not path:
        raise ValueError("no path specified")

    start_list = posixpath.abspath(start).split(posixpath.sep)
    path_list = posixpath.abspath(path).split(posixpath.sep)

    # Work out how much of the filepath is shared by start and path.
    i = len(posixpath.commonprefix([start_list, path_list]))

    rel_list = [posixpath.pardir] * (len(start_list) - i) + path_list[i:]
    if not rel_list:
        return posixpath.curdir
    return posixpath.join(*rel_list)
827435
function path2FolderName(filePath, keepTailSlash){
		var pathSegs = filePath.split("/");
		pathSegs.splice(pathSegs.length -1, 1);
		return keepTailSlash ? pathSegs.join("/") + "/" : pathSegs.join("/");
	}