If you have a path to a file (for example, /home/bob/test/foo.txt) where each subdirectory in the path may or may not exist, how can I create the file foo.txt in a way that uses “/home/bob/test/foo.txt” as the only input instead of creating every nonexistent directory in the path one by one and finally creating foo.txt itself?
If you have a path to a file (for example, /home/bob/test/foo.txt) where each subdirectory
Share
You can use File::Basename and File::Path
I didn’t add any tests to see if the file already exists but that’s pretty easy to add with Perl.