Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract filename from path

Tags:

c

There should be something elegant in Linux API/POSIX to extract base file name from full path

like image 440
pic11 Avatar asked Aug 24 '11 18:08

pic11


People also ask

How do I separate the filename and path in Python?

split() method in Python is used to Split the path name into a pair head and tail. Here, tail is the last path name component and head is everything leading up to that. In the above example 'file. txt' component of path name is tail and '/home/User/Desktop/' is head.

How do I get the filename in PowerShell script?

Use the GetFileName Method to Extract the Filename From a Path in PowerShell. The GetFileName method of the . NET's Path class returns the file name and extension of the specified path. The following example displays the file name and extension from the path C:\pc\test_folder\hello.


1 Answers

See char *basename(char *path).

Or run the command "man 3 basename" on your target UNIX/POSIX system.

like image 69
maerics Avatar answered Sep 21 '22 13:09

maerics