File dirname perl




















Asked 11 years, 5 months ago. Active 5 years, 11 months ago. Viewed 50k times. Add a comment. Active Oldest Votes. Schwern Schwern k 22 22 gold badges silver badges bronze badges.

So dirname does the right job. The shell does exactly the same. Shell and File::Basename's dirname always returns the parent. I still can not understand your confusion.

My mistake. Anatoly Anatoly 9 1 1 bronze badge. To make for a better post, you might expand on your answer, explaining why that particular regex would work for various examples.

This will help your answer make sense to the original poster, and to the many other future readers. Andy A. VladZ VladZ 21 2 2 bronze badges. But File::Basename exists in the standard Perl library, so there's no good reason not to use it. I had cases when I needed execute a Perl script where only perl.

Your approach won't work while mine will be working always. If Perl is installed, then the standard Perl library will also be available. If it's not, you have a broken Perl installation and you should not use it for anything. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.

That function can be found in File::Spec. There's no need to use external modules, with just one line you can have the file name and relative path. If you are using modules and need to apply a path relative to the script directory, the relative path is enough. I guess it depends on what your goal is.

Here is my suggestion:. I had to use this for my script to follow the symlink to the actual file location. All the library-free solutions don't actually work for more than a few ways to write a path think.. My solution looks like below. I have one quirk: I don't have the faintest idea why I have to run the replacements twice.

This is also a sample example for beginners to understand usage better. But will going to return the last level form the path. In this way, we can get the name of the file from the path.

We can also pass the parameter as we want there is no restriction for this. It can take the file path as with or without the suffix mentioned during call of the function in Perl. This is a guide to Perl basename. Here we discuss the introduction, How does basename function work in Perl? You may also have a look at the following articles to learn more —. Submit Next Question. By signing up, you agree to our Terms of Use and Privacy Policy.



0コメント

  • 1000 / 1000