GetFile DateLastModified not working correctly

gacanepa

New Member
Joined
May 17, 2013
Messages
2
Hi everyone,
I am having an issue with the following code, which is intended to retrieve the file's last modification date (I'm only showing the most relevant lines for the sake of brevity):
Code:
Set oFS = CreateObject("Scripting.FileSystemObject")
    Set f = oFS.GetFile("C:\Users\Me\File.txt")
MsgBox CStr(DateValue(f.DateLastModified))
The code is retrieving the date when the file was first created, not when it was last modified. And even if I delete the file File.txt and / or replace it with a newly created one with the same name, it is still displaying the date when the first file was created.
Since this code snippet is inside a for loop ("File.txt" is actually a different name in every loop) I made sure I set to nothing both oFS and f at the end of each loop, but the result is the same.
Any ideas on what I may be doing wrong? All suggestions will be more than welcome.
NOTE: This even happens if I break the loop and try to retrieve a single file's last modified date.
 
Last edited:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hello there

I cannot reproduce your findings. It always gives me the correct date.
A very long shot but... try rebooting the computer maybe such that you can test again from scratch?
 
Upvote 0
Hello there

I cannot reproduce your findings. It always gives me the correct date.
A very long shot but... try rebooting the computer maybe such that you can test again from scratch?

Hello there

I cannot reproduce your findings. It always gives me the correct date.
A very long shot but... try rebooting the computer maybe such that you can test again from scratch?

Thank you so very much for taking the time to check my issue and getting back to me. After many tests I realized that the GetFile method wasn't actually retrieving the date when the file had been first created. I was wrong. I must have been very tired because I didn't realize I was using the wrong argument in the loop. And the GetFile method was retrieving the date when the last file in the loop was created. I changed the variable used in the for loop and it worked like a charm. I don't know what could have been wrong when I tested each file separately, but it's working now. So the bottom line would be, always make sure you're using the right argument when you're looping! :). Thanks again.
 
Upvote 0
Okay, thanks for the feedback !
 
Upvote 0

Forum statistics

Threads
1,216,030
Messages
6,128,418
Members
449,449
Latest member
Quiet_Nectarine_

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top