Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6798731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:45:56+00:00 2026-05-26T18:45:56+00:00

My C# code detects changes in files and folders attributes, using the two following

  • 0

My C# code detects changes in files and folders attributes, using the two following snippets:

// For files
    return (IO.File.GetAttributes(Source) != IO.File.GetAttributes(Dest))

// For folders
    IO.DirectoryInfo SourceInfo = new IO.DirectoryInfo(AbsSource);
    IO.DirectoryInfo DestInfo = new IO.DirectoryInfo(AbsDest);
    return (SourceInfo.Attributes != DestInfo.Attributes);

I noticed that IO.File.GetAttributes seems to work folder folders just as well, and so I was wondering whether I could drop the directory-specific part and just use the one-liner for both files and folders.

Is that possible ? Is reading IO.DirectoryInfo.Attributes equivalent to calling File.GetAttributes?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:45:56+00:00Added an answer on May 26, 2026 at 6:45 pm

    As Hans Passant already pointed out in his answer it is the same thing. The first inidcation is the common base class FileSystemInfo (Attributes property) that FileInfo and DirectoryInfo share.

    But is File.GetAttributes() and DirectoryInfo.Attributes also the same thing?

    To answer that question have a look at the .Net Framework reference source code.

    You can download the reference source code from here .Net Reference Source Code. There you will find that both (DirectoryInfo.Attributes) and File.GetAttributes() both end up calling a internal function on the File class to get the attributes.

    Hope, this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im working in a code that detects changes in a file (a log file)
Apple advises using the following code to detect whether running on an iPad or
I have two .m files. The first is the main code, The second is
The code below demonstarates the problem: java 7 interfaces for watching file changes report
We have some legacy ASP.NET code that detects if a request is secure, and
In a .NET 2.0 C# application I use the following code to detect the
I am unable to detect when input type=file changes its value after user selects
I'm using the InputManager to check if changes to controls are done by user
I want code changes to take effect immediately during development. How can I detect
I want to detect changes for a file, if the file changes, I will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.