Getting file attributes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting file attributes

David Hari
I was looking at the code to get the attributes of a file
(File>>attributes) and i am wondering why it is written that way.
The code calls Directory>>attributesForFileNamed: which searches the
entire directory for the file just to get the dwFileAttributes member of
WIN32_FIND_DATA,

attributesForFileNamed: fileName

    "Answer the attributes of the file named in <fileName>."
    self searchResultsDo: [ :searchResult |
        (searchResult entityName equalsIgnoreCase: fileName) ifTrue: [
^searchResult fileAttributes ]
    ].
    ^nil

Surely a better, and faster, way would be to call the API function
GetFileAttributes or GetFileAttributesEx? I am not sure if there are any
edge cases when using long vs short file names, network or UNC paths,
etc, but i would imagine that GetFileAttributes(Ex) would work just as
well if not better than the method currently used.

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***
Reply | Threaded
Open this post in threaded view
|

Re: Getting file attributes

Todor Todorov
May be GetFileAttributesEx wasn't available at the time or it was only available on NT and not 95.



-----Original Message-----
From: Using Visual Smalltalk for Windows/Enterprise [mailto:[hidden email]] On Behalf Of David Hari
Sent: 13. januar 2011 23:33
To: [hidden email]
Subject: Getting file attributes

I was looking at the code to get the attributes of a file
(File>>attributes) and i am wondering why it is written that way.
The code calls Directory>>attributesForFileNamed: which searches the entire directory for the file just to get the dwFileAttributes member of WIN32_FIND_DATA,

attributesForFileNamed: fileName

    "Answer the attributes of the file named in <fileName>."
    self searchResultsDo: [ :searchResult |
        (searchResult entityName equalsIgnoreCase: fileName) ifTrue: [ ^searchResult fileAttributes ]
    ].
    ^nil

Surely a better, and faster, way would be to call the API function GetFileAttributes or GetFileAttributesEx? I am not sure if there are any edge cases when using long vs short file names, network or UNC paths, etc, but i would imagine that GetFileAttributes(Ex) would work just as well if not better than the method currently used.

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***
Reply | Threaded
Open this post in threaded view
|

Re: Getting file attributes

David Hari
Actually, you're right. MSDN states that it is available in Windows 2000
and later. I thought i had checked MSDN before and that it said 95, i
must have been thinking of something else.

Not sure if it would be worth changing our code to use it, but probably
won't offer much of an advantage.
We discovered a problem in our application when working with files on a
Windows Server 2008 network share. For some reason, GetFileAttributes
was saying that the file did not exist and it was not found using
searchResultsDo:, yet the file clearly existed at the point of the call
(i verified it using Process Monitor). But that probably isn't a
Smalltalk problem...



-----Original Message-----
From: Using Visual Smalltalk for Windows/Enterprise
[mailto:[hidden email]] On Behalf Of Todor Todorov
Sent: Saturday, 15 January 2011 11:48 PM
To: [hidden email]
Subject: Re: Getting file attributes

May be GetFileAttributesEx wasn't available at the time or it was only
available on NT and not 95.



-----Original Message-----
From: Using Visual Smalltalk for Windows/Enterprise
[mailto:[hidden email]] On Behalf Of David Hari
Sent: 13. januar 2011 23:33
To: [hidden email]
Subject: Getting file attributes

I was looking at the code to get the attributes of a file
(File>>attributes) and i am wondering why it is written that way.
The code calls Directory>>attributesForFileNamed: which searches the
entire directory for the file just to get the dwFileAttributes member of
WIN32_FIND_DATA,

attributesForFileNamed: fileName

    "Answer the attributes of the file named in <fileName>."
    self searchResultsDo: [ :searchResult |
        (searchResult entityName equalsIgnoreCase: fileName) ifTrue: [
^searchResult fileAttributes ]
    ].
    ^nil

Surely a better, and faster, way would be to call the API function
GetFileAttributes or GetFileAttributesEx? I am not sure if there are any
edge cases when using long vs short file names, network or UNC paths,
etc, but i would imagine that GetFileAttributes(Ex) would work just as
well if not better than the method currently used.

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***
Reply | Threaded
Open this post in threaded view
|

Re: Getting file attributes

David Hari
In reply to this post by David Hari

Although, VSE2000 does have the method KernelDLL>>getFileAttributes:, but it is only used in Directory class>>exists.

 

 

 

--------------------------

Actually, you're right. MSDN states that it is available in Windows 2000 and later. I thought i had checked MSDN before and that it said 95, i must have been thinking of something else.

 

Not sure if it would be worth changing our code to use it, but probably won't offer much of an advantage.

We discovered a problem in our application when working with files on a Windows Server 2008 network share. For some reason, GetFileAttributes was saying that the file did not exist and it was not found using searchResultsDo:, yet the file clearly existed at the point of the call (i verified it using Process Monitor). But that probably isn't a Smalltalk problem...

 

 

 

-----Original Message-----

From: Using Visual Smalltalk for Windows/Enterprise [mailto:[hidden email]] On Behalf Of Todor Todorov

Sent: Saturday, 15 January 2011 11:48 PM

To: [hidden email]

Subject: Re: Getting file attributes

 

May be GetFileAttributesEx wasn't available at the time or it was only available on NT and not 95.

 

 

 

-----Original Message-----

From: Using Visual Smalltalk for Windows/Enterprise [mailto:[hidden email]] On Behalf Of David Hari

Sent: 13. januar 2011 23:33

To: [hidden email]

Subject: Getting file attributes

 

I was looking at the code to get the attributes of a file

(File>>attributes) and i am wondering why it is written that way.

The code calls Directory>>attributesForFileNamed: which searches the entire directory for the file just to get the dwFileAttributes member of WIN32_FIND_DATA,

 

attributesForFileNamed: fileName

 

    "Answer the attributes of the file named in <fileName>."

    self searchResultsDo: [ :searchResult |

        (searchResult entityName equalsIgnoreCase: fileName) ifTrue: [ ^searchResult fileAttributes ]

    ].

    ^nil

 

Surely a better, and faster, way would be to call the API function GetFileAttributes or GetFileAttributesEx? I am not sure if there are any edge cases when using long vs short file names, network or UNC paths, etc, but i would imagine that GetFileAttributes(Ex) would work just as well if not better than the method currently used.

 

***           this signature added by listserv             ***

*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***

*** for archive browsing and VSWE-L membership management  ***

 

***           this signature added by listserv             ***

*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***

*** for archive browsing and VSWE-L membership management  ***

 

*** this signature added by listserv *** *** Visit http://www.listserv.dfn.de/archives/vswe-l.html *** *** for archive browsing and VSWE-L membership management ***
Reply | Threaded
Open this post in threaded view
|

Re: Getting file attributes

Todor Todorov
In reply to this post by David Hari
MSDN cheats. All API functions require minimum Windows 2000. So you can't trust that. The reason for the current "Minimum Windows 2000" is that the current MSDN supports Windows 2000 and up. You have to look into the historical versions to determine history of the API.

In general, if you have a problem, try it in .Net. If it fails there, then it is probably an issue with your code. If it works, then it is probably a VSE issue.

-----Original Message-----
From: Using Visual Smalltalk for Windows/Enterprise [mailto:[hidden email]] On Behalf Of David Hari
Sent: 16. januar 2011 22:50
To: [hidden email]
Subject: Re: Getting file attributes

Actually, you're right. MSDN states that it is available in Windows 2000 and later. I thought i had checked MSDN before and that it said 95, i must have been thinking of something else.

Not sure if it would be worth changing our code to use it, but probably won't offer much of an advantage.
We discovered a problem in our application when working with files on a Windows Server 2008 network share. For some reason, GetFileAttributes was saying that the file did not exist and it was not found using searchResultsDo:, yet the file clearly existed at the point of the call (i verified it using Process Monitor). But that probably isn't a Smalltalk problem...



-----Original Message-----
From: Using Visual Smalltalk for Windows/Enterprise [mailto:[hidden email]] On Behalf Of Todor Todorov
Sent: Saturday, 15 January 2011 11:48 PM
To: [hidden email]
Subject: Re: Getting file attributes

May be GetFileAttributesEx wasn't available at the time or it was only available on NT and not 95.



-----Original Message-----
From: Using Visual Smalltalk for Windows/Enterprise [mailto:[hidden email]] On Behalf Of David Hari
Sent: 13. januar 2011 23:33
To: [hidden email]
Subject: Getting file attributes

I was looking at the code to get the attributes of a file
(File>>attributes) and i am wondering why it is written that way.
The code calls Directory>>attributesForFileNamed: which searches the entire directory for the file just to get the dwFileAttributes member of WIN32_FIND_DATA,

attributesForFileNamed: fileName

    "Answer the attributes of the file named in <fileName>."
    self searchResultsDo: [ :searchResult |
        (searchResult entityName equalsIgnoreCase: fileName) ifTrue: [ ^searchResult fileAttributes ]
    ].
    ^nil

Surely a better, and faster, way would be to call the API function GetFileAttributes or GetFileAttributesEx? I am not sure if there are any edge cases when using long vs short file names, network or UNC paths, etc, but i would imagine that GetFileAttributes(Ex) would work just as well if not better than the method currently used.

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***

***           this signature added by listserv             ***
*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***
*** for archive browsing and VSWE-L membership management  ***
Reply | Threaded
Open this post in threaded view
|

SV: Getting file attributes

Thomas Antser
In reply to this post by David Hari

We have been using that since at least 1996 - if the comment is correct…

 

/Thomas

 

File class>>writeDisabled: fileName

        "Answer true if read only bit for

         the file named fileName is set."

        "910108  TA  c"

        "910606  TA  win conv"

        "960227  TA  VST"

 

    | flags |

 

    flags := KernelLibrary getFileAttributes: fileName asParameter.

    (flags = InvalidHandleValue) ifTrue: [^self osError].

    ^((flags & FileAttributeReadonly) = FileAttributeReadonly)

 

Från: Using Visual Smalltalk for Windows/Enterprise [mailto:[hidden email]] För David Hari
Skickat: den 16 januari 2011 23:09
Till: [hidden email]
Ämne: Re: Getting file attributes

 

Although, VSE2000 does have the method KernelDLL>>getFileAttributes:, but it is only used in Directory class>>exists.

 

 

 

--------------------------

Actually, you're right. MSDN states that it is available in Windows 2000 and later. I thought i had checked MSDN before and that it said 95, i must have been thinking of something else.

 

Not sure if it would be worth changing our code to use it, but probably won't offer much of an advantage.

We discovered a problem in our application when working with files on a Windows Server 2008 network share. For some reason, GetFileAttributes was saying that the file did not exist and it was not found using searchResultsDo:, yet the file clearly existed at the point of the call (i verified it using Process Monitor). But that probably isn't a Smalltalk problem...

 

 

 

-----Original Message-----

From: Using Visual Smalltalk for Windows/Enterprise [mailto:[hidden email]] On Behalf Of Todor Todorov

Sent: Saturday, 15 January 2011 11:48 PM

To: [hidden email]

Subject: Re: Getting file attributes

 

May be GetFileAttributesEx wasn't available at the time or it was only available on NT and not 95.

 

 

 

-----Original Message-----

From: Using Visual Smalltalk for Windows/Enterprise [mailto:[hidden email]] On Behalf Of David Hari

Sent: 13. januar 2011 23:33

To: [hidden email]

Subject: Getting file attributes

 

I was looking at the code to get the attributes of a file

(File>>attributes) and i am wondering why it is written that way.

The code calls Directory>>attributesForFileNamed: which searches the entire directory for the file just to get the dwFileAttributes member of WIN32_FIND_DATA,

 

attributesForFileNamed: fileName

 

    "Answer the attributes of the file named in <fileName>."

    self searchResultsDo: [ :searchResult |

        (searchResult entityName equalsIgnoreCase: fileName) ifTrue: [ ^searchResult fileAttributes ]

    ].

    ^nil

 

Surely a better, and faster, way would be to call the API function GetFileAttributes or GetFileAttributesEx? I am not sure if there are any edge cases when using long vs short file names, network or UNC paths, etc, but i would imagine that GetFileAttributes(Ex) would work just as well if not better than the method currently used.

 

***           this signature added by listserv             ***

*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***

*** for archive browsing and VSWE-L membership management  ***

 

***           this signature added by listserv             ***

*** Visit  http://www.listserv.dfn.de/archives/vswe-l.html ***

*** for archive browsing and VSWE-L membership management  ***

 

*** this signature added by listserv *** *** Visit http://www.listserv.dfn.de/archives/vswe-l.html *** *** for archive browsing and VSWE-L membership management ***

*** this signature added by listserv *** *** Visit http://www.listserv.dfn.de/archives/vswe-l.html *** *** for archive browsing and VSWE-L membership management ***