Fix all links in generated files to other generated files to point to top
level of generated docs dir.

@param {Array} htmlFiles List of html files found in generated dir.
196489
function fixAllLinks(htmlFiles) {
  const writePromises = [];
  htmlFiles.forEach(file => {
    // Update links in each html file to match flattened file structure.
    writePromises.push(fixLinks(`${docPath}/${file}.html`));
  });
  return Promise.all(writePromises);
}
986913
function (urlpath, dirs) {
    dirs.forEach(function (val, idx) {
        redirectTo(urlpath, false);
        addDeepDir(urlpath, val);
    });
}
527762
def setFilepaths(self, filepaths):
        
        self.setFilepath(os.path.pathsep.join(filepaths))
265832
function cleanLinks( el ) {
		var i;
		for ( i = 0; i < el.length; i++ ) {
			el[ i ].innerHTML = cleanPath( el[ i ].innerHTML );
		}
	}
347910
public void setFilePaths(String... filePaths) {
		Path[] paths = new Path[filePaths.length];
		for (int i = 0; i < paths.length; i++) {
			paths[i] = new Path(filePaths[i]);
		}
		setFilePaths(paths);
	}
1104419
private void addCurrentDirFiles(List<File> theFiles, List<File> theDirs, File currentDir) {
    File dirs[] = currentDir.listFiles(new FileFilter() {

      @Override
      public boolean accept(File file) {
        return file.isDirectory() && !file.getName().startsWith(".") && !file.getName().equals("META-INF");
      }
      
    });
    
    File htmlFiles[] = currentDir.listFiles(new FileFilter() {

      @Override
      public boolean accept(File file) {
        return !file.isDirectory() && file.isFile() && file.canRead() && !file.getName().startsWith(".") && (file.getName().endsWith(".html") || file.getName().endsWith(".htm"));
      }
      
    });
    
    if(dirs != null && dirs.length > 0) {
      theDirs.addAll(Arrays.asList(dirs));
    }
    if(htmlFiles != null && htmlFiles.length > 0) {
      theFiles.addAll(Arrays.asList(htmlFiles));
    }
  }
661311
function (targetFilePath, abspaths) {
    // Change 'assets/mdeditor.min.js' to 'assets/' and 'mdeditor.min.js'
    var pathFilename = _splitPathAndFilename(targetFilePath);
    var targetPath = pathFilename[0];
    var targetFilename = pathFilename[1];

    // bug fix: assets/xxxxxxxx.mdeditor.min.js, xxxxxxxx can't contain '/' or white character
    // otherwise 'assets/mdeditor/1111.mmm.min.js' matched target filename: 'assets/mmm.min.js', which is incorrect.
    var filenamePattern = new RegExp(targetPath + '[^\\/\\s]+?\\.' + targetFilename);

    // Find the revision file based on targetFilePath defined in html template, if there are multiple files matched, pick up the latest one.
    var revTargetFilePath = null;
    var revTargetFileModifyTime = null;
    for (var index in abspaths) {
        if (abspaths[index].match(filenamePattern)) { // there could be more than one revision files matched filenamePattern
            // match the first revision file.
            if (revTargetFilePath === null) {
                revTargetFilePath = abspaths[index];
            // match the one more revision files, pick up the latest files.
            } else {
                if (revTargetFileModifyTime === null) {
                    revTargetFileModifyTime = fs.lstatSync(revTargetFilePath).mtime;
                }
                var currentFileModifyTime = fs.lstatSync(abspaths[index]).mtime;
                if (currentFileModifyTime > revTargetFileModifyTime) {
                    revTargetFilePath = abspaths[index];
                    revTargetFileModifyTime = currentFileModifyTime;
                }
            }
        }
    }
    if (revTargetFilePath === null) {
        grunt.warn('In the file: ' + templateFilename + ', the target filename: ' + targetFilePath + ' has not been handled to produce a corresponding revision file.');
    }
    return revTargetFilePath;
  }
489436
public static void deleteFilesRecursively( File... files ) throws IOException {

		if( files == null )
			return;

		List<File> filesToDelete = new ArrayList<> ();
		filesToDelete.addAll( Arrays.asList( files ));
		while( ! filesToDelete.isEmpty()) {
			File currentFile = filesToDelete.remove( 0 );
			if( currentFile == null
					|| ! currentFile.exists())
				continue;

			// Non-empty directory: add sub-files and reinsert the current directory after
			File[] subFiles = currentFile.listFiles();
			if( subFiles != null && subFiles.length > 0 ) {
				filesToDelete.add( 0, currentFile );
				filesToDelete.addAll( 0, Arrays.asList( subFiles ));
			}

			// Existing file or empty directory => delete it
			else if( ! currentFile.delete())
				throw new IOException( currentFile.getAbsolutePath() + " could not be deleted." );
		}
	}
1127692
private static void alterHtmlDocs(Options opt, String outputFolder, String packageName, String className,
	    String htmlFileName, Pattern insertPointPattern, RootDoc root) throws IOException {
	// setup files
	File output = new File(outputFolder, packageName.replace(".", "/"));
	File htmlFile = new File(output, htmlFileName);
	File alteredFile = new File(htmlFile.getAbsolutePath() + ".uml");
	if (!htmlFile.exists()) {
	    System.err.println("Expected file not found: " + htmlFile.getAbsolutePath());
	    return;
	}

	// parse & rewrite
	BufferedWriter writer = null;
	BufferedReader reader = null;
	boolean matched = false;
	try {
	    writer = new BufferedWriter(new OutputStreamWriter(new
		    FileOutputStream(alteredFile), opt.outputEncoding));
	    reader = new BufferedReader(new InputStreamReader(new
		    FileInputStream(htmlFile), opt.outputEncoding));

	    String line;
	    while ((line = reader.readLine()) != null) {
		writer.write(line);
		writer.newLine();
		if (!matched && insertPointPattern.matcher(line).matches()) {
		    matched = true;
			
		    String tag;
		    if (opt.autoSize)
		        tag = String.format(UML_AUTO_SIZED_DIV_TAG, className);
		    else
                tag = String.format(UML_DIV_TAG, className);
		    if (opt.collapsibleDiagrams)
		    	tag = String.format(EXPANDABLE_UML, tag, "Show UML class diagram", "Hide UML class diagram");
		    writer.write("<!-- UML diagram added by UMLGraph version " +
		    		Version.VERSION + 
				" (http://www.spinellis.gr/umlgraph/) -->");
		    writer.newLine();
		    writer.write(tag);
		    writer.newLine();
		}
	    }
	} finally {
	    if (writer != null)
		writer.close();
	    if (reader != null)
		reader.close();
	}

	// if altered, delete old file and rename new one to the old file name
	if (matched) {
	    htmlFile.delete();
	    alteredFile.renameTo(htmlFile);
	} else {
	    root.printNotice("Warning, could not find a line that matches the pattern '" + insertPointPattern.pattern() 
		    + "'.\n Class diagram reference not inserted");
	    alteredFile.delete();
	}
    }
1265869
function workTextFiles() {
        return indexFiles().concat(srcFiles()).concat(allTestFiles()).concat(otherJsFiles()).concat(otherNonJsFiles()).concat(taskFiles()).concat(cssFiles())
            .concat(toolsShellFiles()).concat(commonJsFiles()).concat(htmlTemplateFiles()).concat(pythonFiles()).concat(textDataFiles());
    }
925916
private function appendCollectedFileAndChanges(): void
    {
        if (!empty($this->currentFile)) {
            foreach ($this->currentChanges as $change) {
                $this->currentFile->addChange($change);
            }
            $this->files[] = $this->currentFile;
        }
        $this->currentChanges = [];
    }
1041497
def render_linked_js(self, js_files: Iterable[str]) -> str:
        
        paths = []
        unique_paths = set()  # type: Set[str]

        for path in js_files:
            if not is_absolute(path):
                path = self.static_url(path)
            if path not in unique_paths:
                paths.append(path)
                unique_paths.add(path)

        return "".join(
            '<script src="'
            + escape.xhtml_escape(p)
            + '" type="text/javascript"></script>'
            for p in paths
        )
129838
function DocFile (file, contents) {
	this.uri = file;
	this.dir = path.dirname(file);
	this.filename = path.basename(file);
	this.name = this.filename.replace(/\.js$/, '');
	this.contents = contents;
	this.comments = [];
	
	this.process();
}
1094305
private function replaceJavaScriptTags($html, array $javaScriptFiles)
    {
        foreach ($javaScriptFiles['links'] as $key => $file) {
            if (!$this->isExternalJavaScriptFile($file)) {
                $html = str_replace(
                    $javaScriptFiles['tags'][$key],
                    $this->getJavaScriptContent($file),
                    $html
                );
            }
        }

        return $html;
    }
1172269
def generate_html_files(*args):
    '''
    
    '''
    _ = args
    for tag_key, tag_list in SWITCH_DICS.items():
        if tag_key.startswith('dic_') and (not tag_key.endswith('00')):
            __write_add_tmpl(tag_key, tag_list)
            __write_edit_tmpl(tag_key, tag_list)
            __write_view_tmpl(tag_key, tag_list)

    __write_filter_tmpl(TPL_LIST)
    __write_list_tmpl(TPL_LISTINFO)
1088749
function resolveLinks(currentFile, resolveFile, $) {
    var currentDirectory = path.dirname(currentFile);

    return editHTMLElement($, 'a', function($a) {
        var href = $a.attr('href');

        // Don't change a tag without href
        if (!href) {
            return;
        }

        if (LocationUtils.isExternal(href)) {
            $a.attr('target', '_blank');
            return;
        }

        // Split anchor
        var parsed = url.parse(href);
        href = parsed.pathname || '';

        if (href) {
            // Calcul absolute path for this
            href = LocationUtils.toAbsolute(href, currentDirectory, '.');

            // Resolve file
            href = resolveFile(href);

            // Convert back to relative
            href = LocationUtils.relative(currentDirectory, href);
        }

        // Add back anchor
        href = href + (parsed.hash || '');

        $a.attr('href', href);
    });
}
591706
function files(path, ...matchers) {
	if ( matchers.length ) {
		return listFiles(path.replace(/\\/g, '/'), matchers);
	}

	let rs = [];
	if( isDirectoryExists(path) ) {
		let ls = fs.readdirSync(path);
		ls.forEach((file, index) => rs.push(path + "/" + file));
	}
	return rs;
}