Will this function do what I need?
The AM post already explained it pretty well: File::Spec generally just checks whether a string looks like an absolute pathname - it does not verify whether the file really exists or what its absolute pathname really is. For example, file_name_is_absolute("/tmp/../home") on a *NIX system will normally return true. If there is a symlink /tmp/badlink that points to a nonexistent location, file_name_is_absolute("/tmp/badlink") will still return true, because it looks like an absolute path. So if "what you need" is to determine whether a user entered something that looks like an absolute path, then yes, File::Spec is the right tool. (Note that File::Spec isn't completely "hands off" in terms of the filesystem in all of its functions, for example its rel2abs will use Cwd.)
To do filename resolution that consults the file system (and does stuff like resolve symlinks), see abs_path from Cwd. (I took it a step further and implemented detailed symlink chain resolution (e.g. if you've got symlink1→symlink2→symlink3→target) in my relink tool - PM node on that.)
In reply to Re: Determining if file path is absolute
by haukex
in thread Determining if file path is absolute
by nysus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |