Old Dog, new tricks

Posted by jmls on 29-Mar-2011 13:00

Well, I never.  10.2B03

DEF VAR lv_file AS CHAR NO-UNDO INIT "c:\temp".

ASSIGN FILE-INFO:FILE-NAME = SEARCH(lv_File).

MESSAGE "1" lv_File SKIP

        "2" SEARCH(lv_File) SKIP

        "3" FILE-INFO:FILE-NAME  SKIP

        "4" FILE-INFO:FULL-PATHNAME

        VIEW-AS ALERT-BOX.

What's wrong with this ? Well, it doesn't work.

Now, I'm sure that at one stage (v3 - v10) it used to ...

from the documentation:

1)  Use the SEARCH function to ensure that procedures that get input  from external data files are independent of specific directory paths. The  files must be in one of the directories or libraries defined in the PROPATH environment variable

which makes sense of why this isn't working

BUT .. THEN ..

2) If you provide a fully qualified pathname, SEARCH checks if the file exists. In this case, SEARCH does not search directories on the PROPATH.

AFAIK, "c:\temp" is a fully qualified pathname

Now, change "c:\temp" to "c:\temp\somefile.txt"

AND IT NOW WORKS. AAARRRGGH

IOW, different behaviour for directories and files. not good.

All Replies

Posted by Thomas Mercer-Hursh on 29-Mar-2011 13:23

AFAIR, SEARCH has never worked on directories.  Pre-FILE-INFO, there were various kludges like putting a file in the target in order to have something to SEARCH for.

Posted by Admin on 29-Mar-2011 13:26

I can't remember that SEARCH ever returned directories.

FILE-INFO does look for files and directories. But when SEARCH already returns ? (because your are trying to lookup a dir, not a file), FILE-INFO will fail as well.

Posted by jmls on 29-Mar-2011 13:31

My point is that c:\temp is a fully-qualified pathname

Posted by Thomas Mercer-Hursh on 29-Mar-2011 13:35

Allow me to quote from the first two lines of the manual:

Searches the directories and libraries defined in the PROPATH environment variable for a file. The
SEARCH function returns the full pathname of the file unless it is found in your current working
directory.

Note the word "file".

Posted by jmls on 29-Mar-2011 13:41

meh.

A directory is a file. A special file, granted, but a file nonetheless.

On 29 March 2011 19:35, Thomas Mercer-Hursh

Posted by Admin on 29-Mar-2011 13:46

A directory is a file. A special file, granted, but a file nonetheless.

 

Not many people on windows would probably share that view.

Posted by Thomas Mercer-Hursh on 29-Mar-2011 14:04

Heck, even Unixieans wouldn't necessarily expect file to include directories in most cases.

Posted by jmls on 29-Mar-2011 14:06

.net disagrees with you

// get the file attributes for file or directory

FileAttributes attr = File.GetAttributes(@"c:\Temp");

//detect whether its a directory or file

if((attr & FileAttributes.Directory) == FileAttributes.Directory)

MessageBox.Show("Its a directory");

else

MessageBox.Show("Its a file");

Posted by Admin on 29-Mar-2011 14:11

.net disagrees with you

Using it each day, I got used to that

Posted by jmls on 29-Mar-2011 14:21

rotflmao

This thread is closed