Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in R Programming by (5.3k points)

Is there a way to extract the file name from the file full path (part of a file path) without the hassle of manipulating string?

The equivalent in Java would be:

File f = new File ("C:/some_dir/a")

f.getName() //output a

f.getFullAbsolutePath() //output c:/some_dir/a

1 Answer

0 votes
by

To extract file name from full file path, use the basename function that removes all of the path up to and including the last path separator.

For example:

basename('C:/Users/intellipaat/Desktop/BLOG/files/session-info.R')

[1] "session-info.R"

To get the directory name, use the following:

dirname('C:/Users/intellipaat/Desktop/BLOG/files/session-info.R')

[1] "C:/Users/intellipaat/Desktop/BLOG/files"

Browse Categories

...