Generate unique directory name of form:
basedir/fileStem<time-in-nanos>

@param baseDir
@param fileStem
@return unique dir name
430863
private static String createTempDirectory(String baseDir, String fileStem) {
        Long nano = new Long(System.nanoTime());
        return baseDir + File.separator + fileStem + nano;
    }
102989
private File getBaseDir( File path)
    {
    return
      path == null?
      baseDir_ :
      
      path.isAbsolute()?
      path :

      new File( baseDir_, path.getPath());
    }
509668
protected synchronized String getFileName(Map result, String fileType) {
        String exname = getExName(result);
        String crid;
        if (getValueOr(result, "seasonal_dome_applied", "N").equals("Y")) {
            crid = "SN";
        } else {
            crid = getCrid(result);
        }
        if (exname.length() == 10) {
            if (crid.equals("XX") || crid.equals("FA")) {
                crid = exname.substring(exname.length() - 2, exname.length());
            }
        }

        String ret;
        if (exToFileMap.containsKey(exname + "_" + crid)) {
            return exToFileMap.get(exname + "_" + crid) + fileType;
        } else {
            ret = exname;
            if (ret.equals("")) {
                ret = "TEMP0001";
            } else {
                try {
                    if (ret.endsWith(crid)) {
                        ret = ret.substring(0, ret.length() - crid.length());
                    }
                    // If the exname is too long
                    if (ret.length() > 8) {
                        ret = ret.substring(0, 8);
                    }
                    // If the exname do not follow the Dssat rule
                    if (!ret.matches("[\\w ]{1,6}\\d{2}$")) {
                        if (ret.length() > 6) {
                            ret = ret.substring(0, 6);
                        }
                        ret += "01";
                    }
                } catch (Exception e) {
                    ret = "TEMP0001";
                }
            }

            // Special handling for batch
            if (exname.matches(".+_\\d+_b\\S+(__\\d+)?$")) {
                int idx = exname.lastIndexOf("_b") + 2;
                ret += "B" + exname.substring(idx).replaceAll("__\\d+$", "");
            }

            // Find a non-repeated file name
            int count;
            while (fileNameSet.contains(ret + "." + crid)) {
                try {
                    count = Integer.parseInt(ret.substring(ret.length() - 2, ret.length()));
                    count++;
                } catch (Exception e) {
                    count = 1;
                }
                ret = ret.replaceAll("\\w{2}$", String.format("%02d", count));
            }
        }

        exToFileMap.put(exname + "_" + crid, ret + "." + crid);
        fileNameSet.add(ret + "." + crid);

        return ret + "." + crid + fileType;
    }
620477
public static File createTmpDir(String directoryName) {
        File tmpDir = new File(System.getProperty("java.io.tmpdir"));
        File testDir = new File(tmpDir, directoryName);
        if(!testDir.mkdir()) {
            throw new ResourceUtilException("Can't create directory: " + testDir.getAbsolutePath());
        }
        testDir.deleteOnExit();
        return testDir;
    }
497945
public static File newFile(File baseDir, String... segments) {
        File f = baseDir;
        for (String segment : segments) {
            f = new File(f, segment);
        }
        return f;
    }
23437
public static File writeFileToTempDirectory(final byte[] data, final String fileName) {
		try {
			File file = createTempDirectory();
			File out = new File(file, fileName);
			out.deleteOnExit();
			file.deleteOnExit();
			return writeDataToFile(data, out);
		} catch (IOException e) {
			JKExceptionUtil.handle(e);
			return null;
		}
	}
347196
public static void setBaseDirectory(@NonNull File f){
        Preconditions.checkState(f.exists() && f.isDirectory(), "Specified base directory does not exist and/or is not a directory: %s", f.getAbsolutePath());
        baseDirectory = f;
    }
343810
@Nonnull
  public static FileIOError renameDir (@Nonnull final File aSourceDir, @Nonnull final File aTargetDir)
  {
    ValueEnforcer.notNull (aSourceDir, "SourceDirectory");
    ValueEnforcer.notNull (aTargetDir, "TargetDirectory");

    // Does the source directory exist?
    if (!FileHelper.existsDir (aSourceDir))
      return EFileIOErrorCode.SOURCE_DOES_NOT_EXIST.getAsIOError (EFileIOOperation.RENAME_DIR, aSourceDir);

    // Are source and target different?
    if (EqualsHelper.equals (aSourceDir, aTargetDir))
      return EFileIOErrorCode.SOURCE_EQUALS_TARGET.getAsIOError (EFileIOOperation.RENAME_DIR, aSourceDir);

    // Does the target directory already exist?
    if (aTargetDir.exists ())
      return EFileIOErrorCode.TARGET_ALREADY_EXISTS.getAsIOError (EFileIOOperation.RENAME_DIR, aTargetDir);

    // Is the source a parent of target?
    if (FileHelper.isParentDirectory (aSourceDir, aTargetDir))
      return EFileIOErrorCode.TARGET_IS_CHILD_OF_SOURCE.getAsIOError (EFileIOOperation.RENAME_DIR,
                                                                      aSourceDir,
                                                                      aTargetDir);

    // Is the source parent directory writable?
    final File aSourceParentDir = aSourceDir.getParentFile ();
    if (aSourceParentDir != null && !aSourceParentDir.canWrite ())
      return EFileIOErrorCode.SOURCE_PARENT_NOT_WRITABLE.getAsIOError (EFileIOOperation.RENAME_DIR, aSourceDir);

    // Is the target parent directory writable?
    final File aTargetParentDir = aTargetDir.getParentFile ();
    if (aTargetParentDir != null && aTargetParentDir.exists () && !aTargetParentDir.canWrite ())
      return EFileIOErrorCode.TARGET_PARENT_NOT_WRITABLE.getAsIOError (EFileIOOperation.RENAME_DIR, aTargetDir);

    // Ensure parent of target directory is present
    FileHelper.ensureParentDirectoryIsPresent (aTargetDir);

    try
    {
      final EFileIOErrorCode eError = aSourceDir.renameTo (aTargetDir) ? EFileIOErrorCode.NO_ERROR
                                                                       : EFileIOErrorCode.OPERATION_FAILED;
      return eError.getAsIOError (EFileIOOperation.RENAME_DIR, aSourceDir, aTargetDir);
    }
    catch (final SecurityException ex)
    {
      return EFileIOErrorCode.getSecurityAsIOError (EFileIOOperation.RENAME_DIR, ex);
    }
  }
510249
function getNewFilename(list, name) {
  if (list.indexOf(name) === -1) {
    return name;
  }
  const parsed = parseFilename(name);
  const base = parsed.base;
  const ext = parsed.ext;
  if (!base) {
    const newName = getNextNumberName(ext);
    return getNewFilename(list, newName);
  } else {
    const basename = getNextNumberName(base);
    return getNewFilename(list, `${basename}${ext}`);
  }
}
85234
public TempDir createTempDir(String originalName) throws IOException {
        if (!open.get()) {
            throw VFSMessages.MESSAGES.tempFileProviderClosed();
        }
        final String name = createTempName(originalName + "-", "");
        final File f = new File(providerRoot, name);
        for (int i = 0; i < RETRIES; i++) {
            if (f.mkdirs()) {
                return new TempDir(this, f);
            }
        }
        throw VFSMessages.MESSAGES.couldNotCreateDirectory(originalName,RETRIES);
    }
35881
public static FilesIterator<String> getRelativeNamesIterator(File baseDir) {
		return new FilesIterator<String>(baseDir, Strategy.RELATIVE_NAMES);
	}
1158537
def make_tmpdir_name(base)
      t = Time.now.strftime('%Y%m%d')
      name = "#{base}#{t}-#{Process.pid}-#{rand(0x100000000).to_s(36)}"
      File.join(Dir.tmpdir, name)
    end
63397
private static List<String> findFiles(String baseDirName, String targetFileName) {

        List<String> classFiles = new ArrayList<>();
        String tempName = null;
        File baseDir = new File(baseDirName);
        if (!baseDir.exists() || !baseDir.isDirectory()) {

        } else {
            String[] filelist = baseDir.list();
            for (int i = 0; i < (filelist != null ? filelist.length : 0); i++) {
                File readfile = new File(baseDirName + File.separator + filelist[i]);
                if (readfile.isDirectory()) {
                    classFiles.addAll(findFiles(baseDirName + File.separator + filelist[i], targetFileName));
                } else {
                    tempName = readfile.getName();
                    if (wildcardMatch(targetFileName, tempName)) {
                        String classname;
                        String tem = readfile.getAbsoluteFile().toString().replaceAll("\\\\", "/");
                        classname = tem.substring(tem.indexOf("/classes") + "/classes".length() + 1,
                                tem.indexOf(".class"));
                        classFiles.add(classname.replaceAll("/", "."));
                    }
                }
            }
        }
        return classFiles;
    }
319043
function getUniqueFilename(base, filename) {
    if (!filename) {
        filename = base;
        base = '/';
    }

    filename = path.resolve(base, filename);
    var ext = path.extname(filename);
    filename = path.join(path.dirname(filename), path.basename(filename, ext));

    var _filename = filename+ext;

    var i = 0;
    while (fs.existsSync(filename)) {
        _filename = filename+'_'+i+ext;
        i = i + 1;
    }

    return path.relative(base, _filename);
}
892747
public DependencyInfo createDependencyInfo(File basedir, String filename) {
        DependencyInfo dependency;
        try {
            File dependencyFile = new File(basedir, filename);
            String sha1 = ChecksumUtils.calculateSHA1(dependencyFile);
            dependency = new DependencyInfo(sha1);
            dependency.setArtifactId(dependencyFile.getName());
            dependency.setFilename(dependencyFile.getName());

            // system path
            try {
                dependency.setSystemPath(dependencyFile.getCanonicalPath());
            } catch (IOException e) {
                dependency.setSystemPath(dependencyFile.getAbsolutePath());
            }

            // populate hints
            if (calculateHints) {
                DependencyHintsInfo hints = HintUtils.getHints(dependencyFile.getPath());
                dependency.setHints(hints);
            }

            // additional sha1s
            // MD5
            if (calculateMd5) {
                String md5 = ChecksumUtils.calculateHash(dependencyFile, HashAlgorithm.MD5);
                dependency.addChecksum(ChecksumType.MD5, md5);
            }

            // handle JavaScript files
            if (filename.toLowerCase().matches(JAVA_SCRIPT_REGEX)) {
                Map<ChecksumType, String> javaScriptChecksums;
                try {
                    javaScriptChecksums = new HashCalculator().calculateJavaScriptHashes(dependencyFile);
                    if (javaScriptChecksums == null || javaScriptChecksums.isEmpty()) {
                        logger.debug("Failed to calculate javaScript hash: {}", dependencyFile.getPath());
                    }
                    for (Map.Entry<ChecksumType, String> entry : javaScriptChecksums.entrySet()) {
                        dependency.addChecksum(entry.getKey(), entry.getValue());
                    }
                } catch (Exception e) {
                    logger.warn("Failed to calculate javaScript hash for file: {}, error: {}", dependencyFile.getPath(), e.getMessage());
                    logger.debug("Failed to calculate javaScript hash for file: {}, error: {}", dependencyFile.getPath(), e.getStackTrace());
                }
            }
            // other platform SHA1
            ChecksumUtils.calculateOtherPlatformSha1(dependency, dependencyFile);
            // super hash
            ChecksumUtils.calculateSuperHash(dependency, dependencyFile);
        } catch (IOException e) {
            logger.warn("Failed to create dependency " + filename + " to dependency list: {}", e.getMessage());
            dependency = null;
        }
        return dependency;
    }
544979
@Override
  public String getStorageDir(DataSegment segment, boolean useUniquePath)
  {
    // This is only called by HdfsDataSegmentPusher.push(), which will always set useUniquePath to false since any
    // 'uniqueness' will be applied not to the directory but to the filename along with the shard number. This is done
    // to avoid performance issues due to excessive HDFS directories. Hence useUniquePath is ignored here and we
    // expect it to be false.
    Preconditions.checkArgument(
        !useUniquePath,
        "useUniquePath must be false for HdfsDataSegmentPusher.getStorageDir()"
    );

    return JOINER.join(
        segment.getDataSource(),
        StringUtils.format(
            "%s_%s",
            segment.getInterval().getStart().toString(ISODateTimeFormat.basicDateTime()),
            segment.getInterval().getEnd().toString(ISODateTimeFormat.basicDateTime())
        ),
        segment.getVersion().replace(':', '_')
    );
  }
1102705
def timestamp_filename(basename, ext=None):
    
    dt = datetime.now().strftime('%Y%m%d-%H%M%S-%f')
    if ext:
        return '%s-%s.%s' % (basename, dt, ext)
    return '%s-%s' % (basename, dt)