In C#, what's the simplest/safest/shortest way to make a file appear as though it has been modified (i.e. change its last modified date) without changing the contents of the file?
The file (both text and binary) should be closed after reading/writing. Closing a file is performed using the fclose() function. fclose(fptr); Here, fptr is a file pointer associated with the file to be closed.
What is File Handling in C? File handling refers to the method of storing data in the C program in the form of an output or input that might have been generated while running a C program in a data file, i.e., a binary file or a text file for future analysis and reference in that very program.
Closing a file clears Buffer contents from RAM or memory. C) Unclosed files occupy memory and PC hangs when on low memory.
System.IO.File.SetLastWriteTimeUtc(fileName, DateTime.UtcNow);
If you don't know whether the file exists, you can use this:
if(!System.IO.File.Exists(fileName)) System.IO.File.Create(fileName).Close(); // close immediately System.IO.File.SetLastWriteTimeUtc(fileName, DateTime.UtcNow)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With