How can I separate a full path into directory and filename?

Viewed 20538
$a = '/etc/init/tree/errrocodr/a.txt'

I want to extract /etc/init/tree/errrocodr/ to $dir and a.txt to $file. How can I do that?

(Editor's note: the original question presumed that you needed a regular expression for that.)

7 Answers
Related