Getting the filenames of all files in a folder [duplicate]

You could do it like that: File folder = new File(“your/path”); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { System.out.println(“File ” + listOfFiles[i].getName()); } else if (listOfFiles[i].isDirectory()) { System.out.println(“Directory ” + listOfFiles[i].getName()); } } Do you want to only get JPEG files or all files?

Better way to check if a Path is a File or a Directory?

From How to tell if path is file or directory: // get the file attributes for file or directory FileAttributes attr = File.GetAttributes(@”c:\Temp”); //detect whether its a directory or file if ((attr & FileAttributes.Directory) == FileAttributes.Directory) MessageBox.Show(“Its a directory”); else MessageBox.Show(“Its a file”); Update for .NET 4.0+ Per the comments below, if you are on … Read more

Convert file: Uri to File in Android

What you want is… new File(uri.getPath()); … and not… new File(uri.toString()); Notes For an android.net.Uri object which is named uri and created exactly as in the question, uri.toString() returns a String in the format “file:///mnt/sdcard/myPicture.jpg”, whereas uri.getPath() returns a String in the format “/mnt/sdcard/myPicture.jpg”. I understand that there are nuances to file storage in Android. … Read more

Reading a file line by line in Go

In Go 1.1 and newer the most simple way to do this is with a bufio.Scanner. Here is a simple example that reads lines from a file: package main import ( “bufio” “fmt” “log” “os” ) func main() { file, err := os.Open(“/path/to/file.txt”) if err != nil { log.Fatal(err) } defer file.Close() scanner := bufio.NewScanner(file) … Read more