Jump to content
Sign in to follow this  
mrider

FileGetAttrib("C:") returns surprising result

Recommended Posts

mrider

Greetings:

I searched forum and didn't find this - however I'm willing to concede that this is probably a "you didn't search well enough" problem.

The following code shows a different answer for "C:" than "C:" (see image at bottom of page):

MsgBox(0, "Attribs", FileGetAttrib("C:") & @LF & FileGetAttrib("C:\"))

However, the following C code does not:

#include <stdio.h>
#include <Windows.h>

void print_attributes(const char * file) {
    DWORD attribs = GetFileAttributes(file);
    if(attribs == INVALID_FILE_ATTRIBUTES) {
        printf("%s did not return valid attributes\n", file);
    } else {
        printf("%c%c%c%c%c%c%c%c%c\n",
            (attribs & FILE_ATTRIBUTE_READONLY)   ? 'R' : ' ',
            (attribs & FILE_ATTRIBUTE_ARCHIVE)    ? 'A' : ' ',
            (attribs & FILE_ATTRIBUTE_SYSTEM)     ? 'S' : ' ',
            (attribs & FILE_ATTRIBUTE_HIDDEN)     ? 'H' : ' ',
            (attribs & FILE_ATTRIBUTE_NORMAL)     ? 'N' : ' ',
            (attribs & FILE_ATTRIBUTE_DIRECTORY)  ? 'D' : ' ',
            (attribs & FILE_ATTRIBUTE_OFFLINE)    ? 'O' : ' ',
            (attribs & FILE_ATTRIBUTE_COMPRESSED) ? 'C' : ' ',
            (attribs & FILE_ATTRIBUTE_TEMPORARY)  ? 'T' : ' '
        );
    }
}

int main(void) {
    print_attributes("C:");
    print_attributes("C:\\");
    return 0;
}

So what gives?

(BTW, Windows XP 32 bit, SP3, pretty much all latest patches and hotfixes...)

(BTW2, the C code shows S, H, and D for both)

post-4896-0-48645900-1380226426_thumb.jp

Edited by mrider

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Share this post


Link to post
Share on other sites
BrewManNH

C: is the root of drive C:, whereas C: is the current directory the working directory is currently set to.

MsgBox(0, "Attribs", FileGetAttrib("C:") & @LF & FileGetAttrib("C:\") & @LF & FileGetAttrib(@WorkingDir))

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
mrider

I only actually rely in the "D", so my code works and this doesn't cause me any problems whatsoever.  But I guess what I found surprising is that AutoIt and the Windows API return different things.  I would have expected AutoIt to use the Windows API.

However, looking more closely at the API for GetFileAttributes, I see that the minimum client is Windows XP.  So presumably AutoIt uses an older API that I don't know about (I almost never write C in Windows...).

 

 

C: is the root of drive C:, whereas C: is the current directory the working directory is currently set to.

 

That makes sense in light of the fact that the AutoIt developers are probably using a different API call than I am.  :)

Edited by mrider

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Share this post


Link to post
Share on other sites
BrewManNH

When I ran your C code from the first post I get this as the output.

 

    D

  SH D

They both give the same results on my Win7 x64 machine.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
mrider

Well then - curiouser and curiouser.  Thanks for trying it. :)


How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Share this post


Link to post
Share on other sites
isosmart

Thanks I will try it later. You are the boss

Share this post


Link to post
Share on other sites
Richard Robertson

Where are you running your C compiled executable from? The working directory will make a difference.

Share this post


Link to post
Share on other sites
mrider

 

Where are you running your C compiled executable from? The working directory will make a difference.

I don't understand that, considering that I have "C:" and "C:" hard-coded.  However, I'm certainly willing to throw it into a few different directories to see what happens...

As I say, this isn't a problem for me.  Just something that I found surprising.


How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Share this post


Link to post
Share on other sites
wraithdu

Since 'C:' refers to the current working directory, it doesn't matter that it's hard coded. So if you run the example from the root of drive C:, in that case C: and C: are equivalent. But if you run it anywhere else, you should see the difference.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×