on 10/25/2004 said:
Your question is not clear to me. Or maybe it is actually two questions?
First, some background. In OS/2 there is no[1] concept of mounting a directory; instead, file systems are referred to by drive letter, there is a current dirve and each drive letter has an associated CWD. A file specification of the form[2] d:\name.ext is interpreted as d:\cwd\name.ext, a name of the form name.ext is interpreted as being in the cwd of the current drive and a name of the form \path\name.ext is interpreted as being in the specified directory on the current drive. I'd like to allow the user to specify any of the forms and convert them to d:\path\name.ext.
First part would be to get the list of all filename, which match the given partial name. Please note, typically this is not a 1:1 relationship but a 1:n because a given partial name can be completed into many actual names.
Of course.
And the second part would be how to prepend the CWD to the file names found. That's a trivial job for the double quote operator or the concatenation operator ".".
Simple but not trivial, because I have to first test whether the drive is already their and whether the absolute path is already there.
Where did you find a function "canon"?
Sorry, that's a typo. It's the canonpath method of the File:Spec module. It's in the online Perl documentation and also in the Dromedary.
Where did you find a function "canon"? glob is the right tool.
No, glob expands wildcards but does not fill in implied components.
Please show us the actual code,
extproc G:\emx\bin\perl -STw
#!/usr/bin/perl -Tw
#
use constant TRUE => 1;
use constant FALSE => '';
use File::Spec qw(catdir catfile splitdir splitpath);
#ARGV=('m*','xyz');
my ($dir,$file)=@ARGV;
print '@ARGV=(',join(',',@ARGV),")\n";
print '$dir =',"$dir\n";
$dir =~ s/^\'?([^\']*)\'?$/$1/;
print '$dir =',"$dir\n";
print '$file=',"$file\n";
$file =~ s/^\'?([^\']*)\'?$/$1/;
print '$file=',"$file\n";
my @dirs=glob($dir);
print '@dirs=(',join(',',@dirs),")\n";
unless (scalar(@dirs) == 1) {
print "$dir matches multiple directory names:\n";
die ' ', join("\n ",@dirs),"\n"
}
die "$dir is an invalid directory name.\n" unless -d $dir;
What is a file specification in your terminlogoy?
I'd probably want to support the OS/2 conventions, which use * and ? as wildcards, with ? matching a single component. I haven't decided whether to restrict the input a bit or to translate into a regular expression. d:\m?file.* would match, e.g., d:\cwd\mafile.cmd, d:\cwd\mbfile.exe, d:\cwd\mcfile.html.
If you want to recurse then use File::Find (and maybe stat and other file information utilities to determine if each file matches the specification).
That's what I wanted to avoid :-(
Thanks.
[1] Well, yes, but that doesn't count. And it leaves the same underlying problem.
[2] OS/2 uses \ as a separator rather than /.