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

  • Home
  • SEARCH
  • 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 64687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:49:44+00:00 2026-05-10T18:49:44+00:00

It appears that Directory.GetFiles() in C# modifies the Last access date of a file.

  • 0

It appears that Directory.GetFiles() in C# modifies the Last access date of a file. I’ve googled for hours and can’t seem to find a work around for this issue. Is there anyway to keep all the MAC (Modified, Accessed, Created) attributes of a file? I’m using Directory.GetDirectories(), Directory.GetFiles(), and FileInfo.

Also, the fi.LastAccessTime is giving strange results — the date is correct, however, the time is off by 2 minutes, or a few hours.

Time of function execution: 10/31/2008 8:35 AM  Program Shows As              Last Access Time 0_PDFIndex.html               - 10/31/2008 8:17:24 AM AdvancedArithmetic.pdf        - 10/31/2008 8:31:05 AM AdvancedControlStructures.pdf - 10/30/2008 1:18:00 PM AoAIX.pdf                     - 10/30/2008 1:18:00 PM AoATOC.pdf                    - 10/30/2008 12:29:51 PM AoATOC2.pdf                   - 10/30/2008 1:18:00 PM  Actual                        Last Access Time 0_PDFIndex.html               - 10/31/2008 8:17 AM AdvancedArithmetic.pdf        - 10/30/2008 12:29 PM AdvancedControlStructures.pdf - 10/30/2008 12:29 PM AoAIX.pdf                     - 10/30/2008 12:29 PM AoATOC.pdf                    - 10/30/2008 12:29 PM AoATOC2.pdf                   - 10/30/2008 12:29 PM 

Below is the method I’m using. If you require more information, please let me know.

Thanks!

public void PopulateTreeView(string directoryValue, ref TreeNode parentNode)         {             string[] directoryArray = Directory.GetDirectories(directoryValue);             string[] fileArray = Directory.GetFiles(directoryValue, '*.*', SearchOption.AllDirectories);              try             {                 #region Directories                 if (directoryArray.Length != 0)                 {                     foreach (string directory in directoryArray)                     {                         DirectoryInfo di = new DirectoryInfo(directory);                          TreeNode dirNode = parentNode.Nodes.Add(di.Name);                          FileNode fn = new FileNode();                         fn.bIsDir = true;                         fn.dir = di;                          dirNode.Tag = fn;                         PopulateTreeView(directory, ref dirNode);                         Application.DoEvents();                      }                 }                 #endregion                  #region Files                 if (fileArray.Length != 0)                 {                     foreach (string file in fileArray)                     {                         FileInfo fi = new FileInfo(file);                          TreeNode fileNode = parentNode.Nodes.Add(fi.Name);                         FileNode fn = new FileNode();                         fn.bIsDir = false;                         fn.file = fi;                          fileNode.Tag = fn;                          fileNode.ImageIndex = 1;                          Console.WriteLine(fi.Name + ' - ' + fi.LastAccessTime);                      }                 }                 #endregion              }             catch (UnauthorizedAccessException)             {                 parentNode.Nodes.Add('Access denied');             }             catch (Exception ex)             {                 MessageBox.Show(ex.ToString());             }             finally             {                 Application.DoEvents();             }         } 

i know the differences between the attributes. What i need is for the file to remain exactly the same all attributes and meta-data, as if my program never touched the file; this includes the last access date.

  • 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. 2026-05-10T18:49:45+00:00Added an answer on May 10, 2026 at 6:49 pm

    I know this is far from ideal, but u can use fsutil (provided with Windows) to disable last access time writing:

    fsutil behavior set disablelastaccess 1 

    Presumably you’d set it back to 0 once done. You can invoke this using Process.Start from C#, but there must be a better programmatic way (calling into Windows API).

    Process.Start('fsutil', 'behavior set disablelastaccess 1').WaitForExit(); 

    Do note that this is a global Windows setting and would also affect disk access from outside your app…

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

Sidebar

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Include TestClass.cpp into the commandline, so the linker can find… May 11, 2026 at 10:07 am
  • added an answer You can get it to work with something around these… May 11, 2026 at 10:07 am
  • added an answer See this question: How to maintain widget's aspect ratio in… May 11, 2026 at 10:07 am

Related Questions

It appears that Directory.GetFiles() in C# modifies the Last access date of a file.
It appears that using perldoc perl gives the list of, e.g. perlre, perlvar, etc.
It appears that in PHP objects are passed by reference. Even assignment operators do
It appears that each app has access to its own config settings, which could
It appears that I can escape command line arguments using single or double quotes:
Based on this question it appears that the default template for CheckStyle will allow
I have a chunk of code where it appears that a variable is changing
In follow up to this question , it appears that some numbers cannot be
I have encapsulated a backup database command in a Try/Catch and it appears that
In SQL Server 2005 Management Studio, it appears that the output of PRINT statements

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.