Saurabh
Saurabh

Reputation: 457

how to get filename from the path

i want to show the filename from the full path. i m getting the full path but don't know how to get that file name with extension? please show me by some example.

code which i use to get full path of the file:

if (resultCode == Activity.RESULT_OK) {
    Log.i("On onActivityResult", "get path");
    Uri selectedVideoUri = data.getData();
    try {
        String filemanagerstring = selectedVideoUri.getPath();
            String selectedVideoPath = getPath(selectedVideoUri);
        if (selectedVideoPath != null) {
        filePath = selectedVideoPath;
        Log.i("VideoFilePath", "" + filePath);
        } else if (filemanagerstring != null) {
        filePath = filemanagerstring;
        Log.i("FilePath", "" + filePath);
        } else {
            Toast.makeText(getApplicationContext(), "Unknown path",
                            Toast.LENGTH_LONG).show();
            Log.e("Bitmap", "Unknown path");
            Log.i("FilePath", "" + filePath);
        }

Upvotes: 0

Views: 11515

Answers (2)

Viswanath Lekshmanan
Viswanath Lekshmanan

Reputation: 10083

Try this, where path is the entire filename including parent directories:

path.getName()

Upvotes: 3

Niranj Patel
Niranj Patel

Reputation: 33238

try this

selectedVideoUri.getLastPathSegment()

Upvotes: 1

Related Questions