File dir = new File(Environment.getExternalStorageDirectory()+"Dir_name_here"); if (dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < children.length; i++) { new File(dir, children[i]).delete(); } }
private void addGroovyJars(List<String> classpathEntries) { File libDir = groovyLibDir.toFile(); String[] jars = libDir.list(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".jar"); } }); for (String jar : jars) { classpathEntries.add(new File(libDir, jar).getAbsolutePath()); } }
public class Testing extends Activity { private static final String TAG = "TEST"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); File appsDir = new File("/data/app"); String[] files = appsDir.list(); for (int i = 0 ; i < files.length ; i++ ) { Log.d(TAG, "File: "+files[i]); } }
File tmpFolder = new File(ClassLoaderTestHelper.localDirPath(conf), "tmp"); if (tmpFolder.exists()) { // Clean up the tmp folder File[] files = tmpFolder.listFiles(); if (files != null) { for (File f: files) { f.delete(); File innerJarFile = ClassLoaderTestHelper.buildJar( folder, className, null, ClassLoaderTestHelper.localDirPath(conf)); File targetJarFile = new File(innerJarFile.getParent(), jarName); ClassLoaderTestHelper.addJarFilesToJar(targetJarFile, libPrefix, innerJarFile); Path path = new Path(targetJarFile.getAbsolutePath()); ClassLoader parent = TestCoprocessorClassLoader.class.getClassLoader(); ClassLoader classLoader = CoprocessorClassLoader.getClassLoader(path, parent, "112", conf); assertNotNull("Classloader should be created", classLoader); String fileToLookFor = "." + className + ".jar"; String[] files = tmpFolder.list(); if (files != null) { for (String f: files) {
private void findPossibleLocations(String basePath, String targetPath, String variantPart, List<String> possibleLocations) { String[] directories = new File(basePath + targetPath).list(); if (directories == null) { return; } if (variantPart.startsWith("/") || variantPart.startsWith("\\")) { variantPart = variantPart.substring(1); } for (String directory : directories) { String possibleLocation = targetPath + "/" + directory; File variantDir = new File(basePath + possibleLocation); if (variantDir.isDirectory() && variantPart.toLowerCase().startsWith(directory.toLowerCase())) { String remainingPart = variantPart.substring(directory.length()); if (remainingPart.length() == 0) { possibleLocations.add(possibleLocation); addPossibleSplitLocations(basePath, possibleLocation, possibleLocations); } else { findPossibleLocations(basePath, possibleLocation, remainingPart, possibleLocations); } } } }
@Test public void testCleanStateStore() throws IOException { File tmpDir = Files.createTempDir(); tmpDir.deleteOnExit(); FileSystem fs = FileSystem.getLocal(new Configuration()); FsDatasetStateStore store = new FsDatasetStateStore(fs, tmpDir.getAbsolutePath()); store.persistDatasetState("dataset1", new JobState.DatasetState("job1", "job1_id1")); store.persistDatasetState("dataset1", new JobState.DatasetState("job1", "job1_id2")); store.persistDatasetState("dataset1", new JobState.DatasetState("job2", "job2_id1")); store.persistDatasetState("", new JobState.DatasetState("job3", "job3_id1")); Properties props = new Properties(); props.setProperty(ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY, tmpDir.getAbsolutePath()); props.setProperty("selection.timeBased.lookbackTime", "0m"); TimeBasedDatasetStoreDatasetFinder datasetFinder = new TimeBasedDatasetStoreDatasetFinder(fs, props); List<DatasetStoreDataset> datasets = datasetFinder.findDatasets(); for (DatasetStoreDataset dataset : datasets) { ((CleanableDataset) dataset).clean(); File jobDir = new File(tmpDir.getAbsolutePath(), dataset.getKey().getStoreName()); Assert.assertEquals(jobDir.list().length, 1); } } }
public String getReasonForFileDeletionFailureInPlainEnglish(File file) { try { if (!file.exists()) return "It doesn't exist in the first place."; else if (file.isDirectory() && file.list().length > 0) return "It's a directory and it's not empty."; else return "Somebody else has it open, we don't have write permissions, or somebody stole my disk."; } catch (SecurityException e) { return "We're sandboxed and don't have filesystem access."; } }
/** * Deletes any files extracted from the JAR during analysis. */ @Override public void closeAnalyzer() { if (tempFileLocation != null && tempFileLocation.exists()) { LOGGER.debug("Attempting to delete temporary files from `{}`", tempFileLocation.toString()); final boolean success = FileUtils.delete(tempFileLocation); if (!success && tempFileLocation.exists()) { final String[] l = tempFileLocation.list(); if (l != null && l.length > 0) { LOGGER.warn("Failed to delete the JAR Analyzder's temporary files from `{}`, " + "see the log for more details", tempFileLocation.getAbsolutePath()); } } } }
@Override public void removeAllRawSessionsOf(OmemoDevice userDevice, BareJid contact) { File contactsDirectory = hierarchy.getContactsDir(userDevice, contact); String[] devices = contactsDirectory.list(); for (String deviceId : devices != null ? devices : new String[0]) { int id = Integer.parseInt(deviceId); OmemoDevice device = new OmemoDevice(contact, id); File session = hierarchy.getContactsSessionPath(userDevice, device); if (!session.delete()) { LOGGER.log(Level.WARNING, "Deleting raw OMEMO session " + session.getAbsolutePath() + "failed."); } } }
private static String getClasspathFromPath(File path) { if (null == path) { return StringUtils.EMPTY; } if (!path.isDirectory()) { return path.getAbsolutePath(); } return Joiner.on(":").skipNulls().join(path.list(FileFileFilter.FILE)); }
@Override public FileStatus[] listStatus(final Path f) throws IOException { final File localf = pathToFile(f); FileStatus[] results; if (!localf.exists()) { return null; } if (localf.isFile()) { return new FileStatus[] { new LocalFileStatus(localf, this) }; } final String[] names = localf.list(); if (names == null) { return null; } results = new FileStatus[names.length]; for (int i = 0; i < names.length; i++) { results[i] = getFileStatus(new Path(f, names[i])); } return results; }
@Override @Nullable public Set<String> getResourcePaths(String path) { String actualPath = (path.endsWith("/") ? path : path + "/"); Resource resource = this.resourceLoader.getResource(getResourceLocation(actualPath)); try { File file = resource.getFile(); String[] fileList = file.list(); if (ObjectUtils.isEmpty(fileList)) { return null; } Set<String> resourcePaths = new LinkedHashSet<>(fileList.length); for (String fileEntry : fileList) { String resultPath = actualPath + fileEntry; if (resource.createRelative(fileEntry).getFile().isDirectory()) { resultPath += "/"; } resourcePaths.add(resultPath); } return resourcePaths; } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Could not get resource paths for " + resource, ex); } return null; } }
static boolean paramFilesExist(final String paramPath) { final File f = new File(paramPath); String[] list = f.getParentFile().list(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.contains(f.getName()); } }); return !f.isDirectory() && (f.exists() || (list != null && list.length > 0)); }
public static ArrayList<String> getAvailableHijackerSessionFiles() { ArrayList<String> files = new ArrayList<String>(); File storage = new File(mStoragePath); if (storage.exists()) { String[] children = storage.list(); if (children != null && children.length > 0) { for (String child : children) { if (child.endsWith(".dhs")) files.add(child); } } } return files; }
private static void readStar() { String curDir = System.getProperty("user.dir"); System.out.println("Current system directory is" + curDir); File dir = new File(curDir); String[] children = dir.list(); if (children == null) { // Either dir does not exist or is not a directory } else { FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".xml"); } }; children = dir.list(filter); if (children != null) { for (String element : children) { xmlFileList.add(element); } } } }
private void addGroovyJars(List<String> classpathEntries) { File libDir = groovyLibDir.toFile(); String[] jars = libDir.list(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".jar"); } }); for (String jar : jars) { classpathEntries.add(new File(libDir, jar).getAbsolutePath()); } }