in reply to Re^3: How do I create folders by trimming the text
in thread How do I create folders by trimming the text
splitpathSplits a path in to volume, directory, and filename portions. On systems with no concept of volume, returns '' for volume.
...
splitdir
The opposite of catdir().
@dirs = File::Spec->splitdir( $directories );
As well, please read How do I post a question effectively?. When you post code, input and output, wrap it in <code> tags so that formatting and whitespace is maintained.
Consider the following script:
#!/usr/bin/perl use strict; use warnings; use File::Spec::Functions qw(splitpath splitdir); my @files = qw( .\folder1\folder11\elementA.xml .\folder1\folder11\elementB.xml .\folder2\folder22\element1.xml .\folder2\folder22\folder222\element11.xml ); for my $file (@files) { my ($volume, $directory, $filename) = splitpath($file); print <<EOT; Input: $file Volume: $volume Directory: $directory Filename: $filename splitdir gives: EOT for my $dir ( splitdir $directory) { print "$dir\n"; } print "\n"; }
outputs:
Input: .\folder1\folder11\elementA.xml Volume: Directory: .\folder1\folder11\ Filename: elementA.xml splitdir gives: . folder1 folder11 Input: .\folder1\folder11\elementB.xml Volume: Directory: .\folder1\folder11\ Filename: elementB.xml splitdir gives: . folder1 folder11 Input: .\folder2\folder22\element1.xml Volume: Directory: .\folder2\folder22\ Filename: element1.xml splitdir gives: . folder2 folder22 Input: .\folder2\folder22\folder222\element11.xml Volume: Directory: .\folder2\folder22\folder222\ Filename: element11.xml splitdir gives: . folder2 folder22 folder222
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: How do I create folders by trimming the text
by Anonymous Monk on Nov 10, 2010 at 18:56 UTC |