Directory.GetFiles storing last access time

It looks like Directory.GetFiles () in C # is changing the date the file was last accessed. I have been working on the Internet for hours and cannot find a job on this issue. In any case, to save all the attributes of the MAC (modified, available, created) file? I use Directory.GetDirectories (), Directory.GetFiles () and FileInfo.

In addition, fi.LastAccessTime gives strange results - the date is correct, but the time is off for 2 minutes or several 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 further information, please let me know.

Thank!

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();
            }
        }

. , , ; .

+3
8

, , fsutil ( Windows), :

fsutil behavior set disablelastaccess 1

, 0 . Process.Start #, ( Windows API).

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

, Windows, ...

+5

. fi.LastWriteTime, , , cmd.

, , .

+1

( , ...)

, - , , Directory.GetFiles 100% .

Filemon , : http://technet.microsoft.com/en-us/sysinternals/bb896642.aspx

+1

, , , ? , , -. , , , , ... , , ?

+1

, , MSDN:

FileSystemInfo API . Refresh, .

, "LastAccessTime" , "" . ""... , .

0

, , .

0

, Google :

NTFS

, , ...

0

, , (, , ).

Google hdd "write protect" .

0
source

Source: https://habr.com/ru/post/1698969/


All Articles