1. dir() in linux
-- start of code
x = dir("*.REQ") -- Get all *.REQ filenames in the current directory.
if atom(x) then
return(0) -- no filenames
end if
-- end of code
This works perfectly on Windows. But not on Linux. On Linux dir("*.REQ")
always returns -1 even tho the current directory contains *.REQ files.
I checked with current_dir() to find out what it thinks the current
directory is. No problem with current directory. And the *.REQ files are
there. But dir("*.REQ") doesn't find them.
It's not a case problem. All the filenames use upper case ".REQ" and the
code uses upper case "*.REQ".
The Euphoria manual, under "dir", says:
"On Windows and DOS st can contain * and ? wildcards to select multiple
files."
Does this mean dir() can't use wildcards on Linux?
The command "ls" understands *.REQ. When I type "ls *.REQ" it works.
If ls understands * why not dir()?
2. Re: dir() in linux
Jerry Story writes:
> The Euphoria manual, under "dir", says:
> "On Windows and DOS st can contain * and ? wildcards
> to select multiple files."
> Does this mean dir() can't use wildcards on Linux?
That's right.
On Windows and DOS, the C library provides
this wildcard functionality. On Linux,
you'll have to write your own Euphoria code to filter out
the filenames that you want/don't want.
Maybe someday I'll get around to enhancing dir on Linux/FreeBSD etc.
Regards,
Rob Craig
Rapid Deployment Software
http://www.RapidEuphoria.com
3. Re: dir() in linux
Unliike in DOS, in Linux is "*.REQ" a valid filename.
The '*' wildcard matching in command line
is generated by the shell.
Martin
----- Original Message -----
From: "Jerry Story" <jstory at edmc.net>
To: "EUforum" <EUforum at topica.com>
Subject: dir() in linux
-- start of code
x = dir("*.REQ") -- Get all *.REQ filenames in the current directory.
if atom(x) then
return(0) -- no filenames
end if
-- end of code
This works perfectly on Windows. But not on Linux. On Linux dir("*.REQ")
always returns -1 even tho the current directory contains *.REQ files.
I checked with current_dir() to find out what it thinks the current
directory is. No problem with current directory. And the *.REQ files are
there. But dir("*.REQ") doesn't find them.
It's not a case problem. All the filenames use upper case ".REQ" and the
code uses upper case "*.REQ".
The Euphoria manual, under "dir", says:
"On Windows and DOS st can contain * and ? wildcards to select multiple
files."
Does this mean dir() can't use wildcards on Linux?
The command "ls" understands *.REQ. When I type "ls *.REQ" it works.
If ls understands * why not dir()?
4. Re: dir() in linux
Rob wrote:
> Jerry Story writes:
>> The Euphoria manual, under "dir", says:
>> "On Windows and DOS st can contain * and ? wildcards
>> to select multiple files."
>> Does this mean dir() can't use wildcards on Linux?
> That's right.
> On Windows and DOS, the C library provides
> this wildcard functionality. On Linux,
> you'll have to write your own Euphoria code to filter out
> the filenames that you want/don't want.
> Maybe someday I'll get around to enhancing dir on Linux/FreeBSD etc.
As far as I can see, if a path without a file name/pattern is given to
dir(), it returns all entries in that folder, right?
This also must apply to Linux, otherwise walk_dir() wouldn't work on
Linux.
So I assume that maybe the following function dir_wild() does what you
want, Jerry. (I only have the possibility to test it on Windows, where
it works as expected.)
Regards,
Juergen
------------------------------------------------------------------------
include file.e
include wildcard.e
integer SLASH
if platform() = LINUX then
SLASH = '/'
else
SLASH = '\\'
end if
function path_end (sequence name)
for i = length(name) to 1 by -1 do
if name[i] = SLASH then
return i
end if
end for
return find(':', name)
end function
global function file_path (sequence name)
-- in : filename, e.g. "c:\\programs\\nicetool.exe"
-- out: path (always with trailing slash), e.g. "c:\\programs\\"
integer p
p = path_end(name)
if p = length(name) or name[p+1] != '.' then
return name[1..p]
else
return name & SLASH
end if
end function
global function file_name (sequence name)
-- in : filename, e.g. "c:\\programs\\nicetool.exe"
-- out: name without path, e.g. "nicetool.exe"
integer p
p = path_end(name) + 1
if p <= length(name) and name[p] != '.' then
return name[p..length(name)]
else
return ""
end if
end function
global function dir_wild (sequence filespec)
object list
sequence name, path, entry, ret
name = file_name(filespec)
if find('?', name) or find('*', name) then
path = file_path(filespec)
if length(path) = 0 then
path = current_dir()
end if
list = dir(path)
if atom(list) then return -1 end if
ret = ""
for i = 1 to length(list) do
entry = list[i]
-- Note from the documentation of wildcard_file():
-- In DOS [or Windows] "*ABC.*" will match all files.
-- wildcard_file("*ABC.*", s) will only match when the file name part
-- has "ABC" at the end (as you would expect).
if wildcard_file(name, entry[D_NAME]) then
ret = append(ret, entry)
end if
end for
if length(ret) = 0 then return -1 end if
return ret
end if
return dir(filespec)
end function
---------------[ Demo ]---------------
object list, std_list
sequence pattern
pattern = "*.REQ"
list = dir_wild(pattern)
-- for testing on DOS or Windows:
if platform() != LINUX then
std_list = dir(pattern)
if equal(list, std_list) then
puts(1, "dir_wild() found the same entries as dir() !")
puts(1, "\n\n")
else
puts(1, "dir_wild() found other entries than dir() !")
puts(1, "\n\n")
puts(1, "-- dir_wild():\n")
end if
end if
if atom(list) then
? list
abort(0)
end if
for i = 1 to length(list) do
puts(1, list[i][D_NAME] & '\n')
end for
------------------------------------------------------------------------
5. Re: dir() in linux
>
> Jerry Story writes:
> > The Euphoria manual, under "dir", says:
> > "On Windows and DOS st can contain * and ? wildcards
> > to select multiple files."
>
> > Does this mean dir() can't use wildcards on Linux?
>
> That's right.
> On Windows and DOS, the C library provides
> this wildcard functionality. On Linux,
> you'll have to write your own Euphoria code to filter out
> the filenames that you want/don't want.
> Maybe someday I'll get around to enhancing dir on Linux/FreeBSD etc.
>
> Regards,
> Rob Craig
> Rapid Deployment Software
> http://www.RapidEuphoria.com
>
I wrote a lindir() function which could use wildcards in the same
way that Windows and DOS does. Also it is able to return more
information
about file permissions for a file. (I cheated and used "ls" for this,
btw the wildcard expansion for /bin/ls is done by the shell, not by
/bin/ls itself.)
If anyone wants this function email me.
jbrown
--