Hello,
I know this subject has been covered,but I don't seem to get it. I have got a cgi script that uploads a file. I am using File::Basename to split the path to extract just the file name and extension. it works fine with Unix path separators, but I can not get it to work when dealing with a windows path. It strips out the path separators, but doesn't give the filename.
If I upload a file called
C:\Documents and Settings\Ryan\My Documents\sample.txt it gives me the full path minus the path separators.
use File::Basename;
my ($name, $path, $suffix);
my $filename_with_path_unix = "/usr/local/sample.txt";
print "path is ";
print $filename_with_path_unix."\n" ;
# test 1, unix
print "TEST #1\n";
( $name, $path, $suffix ) = fileparse( $filename_with_path_unix, "\.[^
+.]*" );
print $name."\n";
print $path."\n";
print $suffix."\n";
print "File is ". $name.$suffix."\n";
#test 2, dos
print "TEST #2\n";
my $filename_with_path_dos = "C:\Documents and Settings\My Documents\s
+ample.txt";
print "path is ".$filename_with_path_dos."\n";
( $name, $path, $suffix ) = fileparse( $filename_with_path_dos, "/.[^.
+]*" );
print $name."\n";
print $path."\n";
print $suffix."\n";
print "File is ". $name.$suffix."\n";
The output for Unix is
sample.txt.
The output for windows is
C:Documents and SettingsMy Documentssample.txt.
Thank you for any help.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.