CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2010
    Posts
    6

    How to get file permissions that are associated with a file?

    This is what I have:
    Code:
    using System;
    using System.IO;
    using System.Text;
    
    namespace File_Permissions
    {
        class Start {
            static void Main(string[] args)
            {
                string dir = "dummy";
                string dir_fil = "dummy/test.txt";
    
                FileAttributes attributes = File.GetAttributes(dir);
                System.Console.WriteLine(" These are the directory 'dummy' attributes : " + attributes.);
            }
        }
    }
    What I'm trying to do is get the attributes of a file/directory that you normally would see when you try to view the "Properties" on a file. I've found these examples, but it's kind of lacking:

    https://www.tutorialspoint.com/file-...sions-in-chash

    What's the best way to view _all_ of these properties? Specifically, I'd like to know how to view permissions, owner, etc. and then print all of this out to the console.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to get file permissions that are associated with a file?

    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: How to get file permissions that are associated with a file?

    Do you mean file permissions or file attributes? These are quite different.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to get file permissions that are associated with a file?

    Victor Nijegorodov

  5. #5
    Join Date
    May 2010
    Posts
    6

    Re: How to get file permissions that are associated with a file?

    Quote Originally Posted by 2kaud View Post
    Do you mean file permissions or file attributes? These are quite different.
    Is there a way to do both of them? Are there "file.printAllPermissions();" and "file.printAllAttributes();"? Or would I need to make that function myself?

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: How to get file permissions that are associated with a file?

    I guess you have to implement it yourself. Just see the examples and documentation and repeat output for each attribute you want to.
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured