Take a file path, read its contents, inject the Bower packages, then write
the new file to disk.

@param  {string} filePath  path to the source file
972241
function injectScripts(filePath) {
  var contents = String($.fs.readFileSync(filePath));
  var fileExt = $.path.extname(filePath).substr(1);
  var fileType = fileTypes[fileExt] || fileTypes['default'];
  var returnType = /\r\n/.test(contents) ? '\r\n' : '\n';

  var newContents = contents.replace(
    fileType.block,
    replaceIncludes(filePath, fileType, returnType)
  );

  if (contents !== newContents) {
    $.fs.writeFileSync(filePath, newContents);

    config.get('on-file-updated')(filePath);
  }
}
564140
function _copyConfigFromFile(filePath, config) {
    LOG.info("Attempting to load configuration file '{}'", filePath);

    var fileConfig = require(filePath);
    _mergeConfig(config, fileConfig);

    LOG.info("Successfully read configuration file '{}'", filePath);
}
697061
void fileWriteCheck(String filePath, AddOnModel addOnModel) {
        File request;
        try {
            request =  new File(filePath).getCanonicalFile();
        } catch (IOException e) {
            error("Error getting canonical path", e);
            throw getException(filePath);
        }

        isForbidden(request, addOnModel);

        boolean success = false;
        if (allowedWriteDirectories.stream()
                .anyMatch(compare -> request.toPath().startsWith(compare.toPath()))) {
            success = true;
        }

        for (String name : forbiddenWriteFilesNames) {
            if (request.getName().equals(name)) {
                success = false;
            }
        }

        if (!success) {
            throw getException(filePath);
        }

        if (!getSecurityManager().getSecureAccess().checkForExistingFileOrDirectory(request.toString())
                || getSecurityManager().getSecureAccess().checkForDirectory(request.toString())) {
            return;
        }
    }
674687
function readdirAsync(filepath){
	return new Promise((resolve, reject)=>{
		fs.readdir(filepath, (err, items)=>{
			if (err) reject(err)
			else resolve(items)
		})
	})
}
361300
function _write(filePath, json) {
        var result = $.Deferred(),
            _file = FileSystem.getFileForPath(filePath);

        if (_file) {

            var content = JSON.stringify(json);
            FileUtils.writeText(_file, content, true)
                .done(function () {
                    result.resolve();
                })
                .fail(function (err) {
                    result.reject();
                });

        } else {
            result.reject();
        }

        return result.promise();
    }
326788
function writeFile(pathToFile, content, verbose) {
  const directory = path.dirname(pathToFile);

  // Create directory if it doesn't exist
  if (!fs.existsSync(directory)) {
    fs.mkdirSync(directory);
  }

  // Try to write file to disk to the given location
  fs.writeFile(pathToFile, content, { flag: 'w' }, (error) => {
    if (error) {
      throw new Error(error);
    }

    // Log success message to the console if in verbose mode only
    if (verbose) {
      const successMessage = `\nVersion file written to ${chalk.green(pathToFile)}`;

      console.log(successMessage);
    }
  });
}
1057700
def file_append(filepath, newcontent, backup=false)
      content = StringIO.new
      
      if self.file_exists?(filepath)
        self.cp filepath, "#{filepath}-previous" if backup
        content = self.file_download filepath
      end
      
      if newcontent.is_a?(StringIO)
        newcontent.rewind
        content.puts newcontent.read
      else
        content.puts newcontent
      end
      
      self.file_upload content, filepath
    end
1072674
function(inputFile, outputFile, content) {
                return Promise()
                .then(function() {
                    var outputFilePath = PathUtils.resolveInRoot(outputFolder, outputFile);

                    return fs.ensureFile(outputFilePath)
                    .then(function() {
                        return fs.copy(inputFile, outputFilePath);
                    });
                });
            }
1311557
function(filepath, data){
      filepath = [].concat(filepath);
      var buf=[].concat(filepath);
      function parse(fileId, refUri, data) {
        var filepath = id2Uri(fileId, refUri, data);
        if(!grunt.file.exists(filepath)){ //file not found
          grunt.log.warn('Source file "' + filepath + '" not found.');
          return;
        }
        buf.unshift(filepath);
        if(filepath.indexOf('.css') != -1){ //if depend a css file
          buf.unshift(CSSFILE_HOLDER);
          return;
        }

        var dependencies = parseDependencies(grunt.file.read(filepath));
        if (dependencies.length) {
          var i = dependencies.length;
          while (i--) {
            parse(dependencies[i], filepath, data);
          }
        }
      }
      filepath.forEach(function(filepath){
        var fileContent = grunt.file.read(filepath);
        parseDependencies(fileContent).forEach(function(id){
          parse(id, filepath, data);
        })
      })
      //filter the same file
      return buf.filter(function(value, index, self){
        return self.indexOf(value) === index;
      });
  }
723246
function createFileTree (filePaths)
{
  var path = require ('path')
    , root = {
    files:      [],
    subfolders: new Map
  };

  filePaths.forEach (function (filename)
  {
    var dir = path.dirname (filename)
      , folderPtr = root;
    if (dir)
      dir.split (path.sep).forEach (function (segment)
      {
        if (!folderPtr.subfolders.has (segment))
          folderPtr.subfolders.set (segment, {
            files:      [],
            subfolders: new Map
          });
        folderPtr = folderPtr.subfolders.get (segment);
      });
    folderPtr.files.push (filename);
  });
  return root;
}
652002
function(filePath, identifier, name) {
    this.filePath = filePath;
    this.identifier = identifier;
    this.name = name ? name : '';
}
1368760
function (path) {
    var pathSep = require('path').sep;
    var dirs = path.split(pathSep);
    var root = '';

    while (dirs.length > 0) {
      var dir = dirs.shift();
      if (dir === '') {
        root = pathSep;
      }
      if (!fs.existsSync(root + dir)) {
        fs.mkdirSync(root + dir);
      }
      root += dir + pathSep;
    }
  }
395719
function newfile(filepath) {
  let dir = path.dirname(filepath);
  if (path.extname(filepath) === '.shp') dir = path.resolve(dir, '..');
  const name = crypto.randomBytes(8).toString('hex');
  return path.join(dir, name);
}
29476
function copyFile(srcPath, desPath) {
    var read = fs.createReadStream(srcPath);
    var write = fs.createWriteStream(desPath);
    read.pipe(write);
    console.log('[info] create file:', desPath);
}
515853
public void addFile(String filename, String filePath) {
        int pathIndex = filePathList.indexOf(filePath);
        if (pathIndex == -1) {
            fileNameList.add(filename);
            filePathList.add(filePath);
        }
    }
488425
public static boolean writeString(String filePath, String content, boolean append) throws IOException {
        return writeString(filePath != null ? new File(filePath) : null, content, append);
    }
1254058
function addCompressionToFile(filePath, compression) {
        var srcFilePath = filePath.replace(rootFolder, "").replace(compression.fileExtension, "");
        var existingFile = files[srcFilePath];
        if (!existingFile) {
            files[srcFilePath] = { compressions: [compression] };
        } else {
            existingFile.compressions.push(compression);
        }
    }