how can i check the size,readonly,archive,hidden,date created time atrributes?

This is a discussion on how can i check the size,readonly,archive,hidden,date created time atrributes? within the C Programming forums, part of the General Programming Boards category; how can i check the size,readonly,archive,hidden,date created time atrributes? i want to write a program in c using some assembly ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    28

    Angry how can i check the size,readonly,archive,hidden,date created time atrributes?

    how can i check the size,readonly,archive,hidden,date created time atrributes?

    i want to write a program in c using some assembly codes like interrupts.

    how can i ?
    anyone help me plz?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You can almost certainly do this without using any assembly code in your project. However, there are different solutions for different OS's. There is a FAQ that explains something like "How do I find all the files in a directory". That would be a good start.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    28
    no i have to do this as it is.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by maifs View Post
    no i have to do this as it is.
    What do you mean "I have to do it as it is"?

    What is the actual wording of your assignment, and what OS are you working on?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    28

    re

    i have made it for checking file size, help me in to check file is readonly, archive,hidden,date and time creation time . in windows xp os.



    Code:
    unsigned int handle;
    void main()
    {
    
    union REGS regs;
    unsigned long int size;
    handle = open("c:\\a.txt",O_RDONLY);
    regs.x.bx = handle;
    regs.h.ah = 0x42;
    regs.h.al = 0x02;
    regs.x.cx = 0;
    regs.x.dx = 0;
    int86(0x21,&regs,&regs);
    *((int*) (&size)) = regs.x.ax;
    *(((int*) (&size))+) = regs.x.dx;
    printf("Size is %d",size);
    
    }

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, can you explain WHY you have to do this using interrupts, since the same information that you are currently getting out can be had using fopen() and fseek() [you are calling the SEEK operation in your intr86 code]. The difference being that the fopen() and fseek() would be portable so you can use it not only in DOS, but also in a Linux or Windows environment.

    Getting the attributes of the file may be harder to do generically.

    Here's a summary of DOS int 21h calls.
    http://bbc.nvg.org/doc/Master%20512%...echb_int21.htm

    Operation 43h may help.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Jan 2009
    Posts
    28
    i want to make it in it. because i want to learn in this.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by maifs View Post
    i want to make it in it. because i want to learn in this.
    But why do you want to learn something that went out of fashion about 10 years ago? It makes about as much sense as saying "Oh, but I REALLY want to know how to repair cars that have mechanical ignition systems, because I want to learn it", rather than learning about modern cars that use electronic ignition systems".

    Note that if you are actually running this on a Windows system, all DOS calls get intercepted by the DOS emulation package, passed into Windows for completion, and then translated back to DOS style content - so you are NOT getting the work done quicker by using the old-style DOS functionality.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    > in windows xp os.
    Otherwise known as

    - Buy Ferrari
    - Take out engine
    - Drag "dobbin the asthmatic wonder horse" out of retirement, and hitch to the now engine-less Ferrari
    - "Giddie up"
    - Wonder why the universe is suddenly so crappy.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,587
    1) Upgrade compiler. Get rid of Turbo C. Better compilers & IDEs: http://cpwiki.sf.net/IDE
    2) Don't use void main: http://cpwiki.sourceforge.net/Void_main
    3) Use up-to-date C functions such as fopen instead of open.
    4) Do it the real way™. Use Windows API instead of interrupts.
    5) And for goodness' sakes, post on only ONE, and I repeat, one forum!
    Last edited by Elysia; 01-08-2009 at 09:41 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    Looks like this was also posted here.

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    This is from Turbo C/C++, and answers some of your questions.

    Code:
    /*
    access   Determines accessibility of a file
    
     Syntax:
       int access(const char *filename, int amode);
    
     Prototype in:
     io.h
    
     Remarks:
    access checks the file named by filename to determine if it exists, and
    whether it can be read, written to, or executed.
    
    The list of amode values is as follows:
    
     Value ณ Description
     ออออออุอออออออออออออออออออออออออออออออออออออ
       06  ณ Check for read and write permission
       04  ณ Check for read permission
       02  ณ Check for write permission
       01  ณ Execute (ignored)
       00  ณ Check for existence of file
    
    Under DOS, all existing files have read access (amode equals 04), so 00 and
    04 give the same result.
    
    Similarly, amode values of 06 and 02 are equivalent because under DOS write
    access implies read access.
    
    If filename refers to a directory, access simply determines whether the
    directory exists.
    
     Return Value:
    If the requested access is allowed, access returns 0.
    
    Otherwise, it returns a value of -1, and the global variable errno is set to
    one of the following:
    
     Errno   ณ
     Setting ณ Description
    อออออออออุออออออออออออออออออออออออออออ
     ENOENT  ณ Path or file name not found
     EACCES  ณ Permission denied
    
     Portability:
    access is available on UNIX systems.
    
     See Also:
     chmod   fstat   stat
    
     Example:
     #include <stdio.h>
     #include <io.h>
    
     int file_exists(char *filename);
    
     int main(void)
     {
       printf("Does NOTEXIST.FIL exist: %s\n",
              file_exists("NOTEXISTS.FIL") ? "YES" : "NO");
       return 0;
     }
    
     int file_exists(char *filename)
     {
       return (access(filename, 0) == 0);
     }
    
    
    
    fstat   Gets open file information.
    
    
     Syntax:
       int fstat(int handle, struct stat *statbuf);
    
     Prototype in:
     sys\stat.h
    
     Remarks:
    fstat stores information in the stat structure about the open file or
    directory associated with handle.
    
    statbuf points to the stat structure (defined in sys\stat.h). That structure
    contains the following fields:
    
       Field    ณ Description
      ===============================================
       st_mode  ณ Bit mask giving information about the open file's mode
       st_dev   ณ Drive number of disk containing the file, or file handle
                ณ if the file is on a device
       st_rdev  ณ Same as st_dev
       st_nlink ณ Set to the integer constant 1
       st_size  ณ Size of the open file in bytes
       st_atime ณ Most recent time the open file was modified
       st_mtime ณ Same as st_atime
       st_ctime ณ Same as st_atime
    
    The stat structure contains three more fields not mentioned here. They
    contain values that are not meaningful under DOS.
    
    The bit mask that gives information about the mode of the open file includes
    the following bits in the following two tables.
    
    One of the following bits will be set:
    
       Bit      ณ Description
      ออออออออออุออออออออออออออออออออออออออออออออออออออออออออออ
       S_IFCHR  ณ Set if handle refers to a device
       S_IFREG  ณ Set if an ordinary file is referred to by handle
    
    One or both of the following bits will be set:
    
       Bit      ณ Description
      ออออออออออุออออออออออออออออออออออออออออออออออออออออออออ
       S_IWRITE ณ Set if user has permission to write to file
       S_IREAD  ณ Set if user has permission to read to file
    
    The bit mask also includes the read/write bits. They are set according to
    the file's permission mode.
    
     Return Value:
    fstat returns 0 if it has successfully retrieved the information about the
    open file.
    
    On error (failure to get the information), it returns -1 and sets the global
    variable errno to EFADF (bad file handle).
    
     Portability:
    fstat is available on UNIX systems.
    
     See Also:
      access    chmod    stat
    
     Example:
     #include <sys\stat.h>
     #include <stdio.h>
     #include <time.h>
    
     int main(void)
     {
        struct stat statbuf;
        FILE *stream;
    
        /* open a file for update */
        if ((stream = fopen("DUMMY.FIL", "w+"))
            == NULL)
        {
           fprintf(stderr, "Cannot open output file.\n");
           return(1);
        }
        fprintf(stream, "This is a test");
        fflush(stream);
    
        /* get information about the file */
        fstat(fileno(stream), &statbuf);
        fclose(stream);
    
        /* display the information returned */
        if (statbuf.st_mode & S_IFCHR)
           printf("Handle refers to a device.\n");
        if (statbuf.st_mode & S_IFREG)
           printf("Handle refers to an ordinary file.\n");
        if (statbuf.st_mode & S_IREAD)
           printf("User has read permission on file.\n");
        if (statbuf.st_mode & S_IWRITE)
           printf("User has write permission on file.\n");
    
        printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev);
        printf("Size of file in bytes: %ld\n", statbuf.st_size);
        printf("Time file last opened: %s\n", ctime(&statbuf.st_ctime));
        return 0;
     }
    

  13. #13
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,587
    Don't feed the trolls -_-
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 06-03-2009, 03:00 PM
  2. Check if a program creates prt scrs
    By Livijn in forum C# Programming
    Replies: 6
    Last Post: 09-11-2008, 05:43 AM
  3. What is the best way to record a process execution time?
    By hanash in forum Linux Programming
    Replies: 7
    Last Post: 03-15-2006, 06:17 AM
  4. writing/reading from file produces double results.
    By stumon in forum C Programming
    Replies: 4
    Last Post: 03-20-2003, 03:01 PM
  5. relating date....
    By Prakash in forum C Programming
    Replies: 3
    Last Post: 09-19-2001, 09:08 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21